Hi PANDEY Prashant!
Welcome to Microsoft Q&A!
To automate the process of building daily partitions on your fact table in SSAS Tabular, you can use a combination of TMSL (Tabular Model Scripting Language) and a stored procedure in SQL Server. Below is a detailed approach to achieve this:
Step-by-Step Guide
- Create a Stored Procedure in SQL Server
First, create a stored procedure that generates the TMSL script for creating partitions dynamically. This stored procedure will loop through the dates from January 1, 2020, to the current date and create partitions accordingly.
CREATE PROCEDURE CreateDailyPartitions
AS
BEGIN
DECLARE @StartDate DATE = '2020-01-01';
DECLARE @EndDate DATE = GETDATE();
DECLARE @CurrentDate DATE = @StartDate;
DECLARE @TMSL NVARCHAR(MAX);
WHILE @CurrentDate <= @EndDate
BEGIN
DECLARE @PartitionName NVARCHAR(50) = 'Partition_Member_' + FORMAT(@CurrentDate, 'ddMMMyyyy');
DECLARE @CalendarID INT = CONVERT(INT, FORMAT(@CurrentDate, 'yyyyMMdd'));
SET @TMSL = '
{
"createOrReplace": {
"object": {
"database": "audex-analyse-dev-ssas",
"table": "audexdw fact_viewing_session_member",
"partition": "' + @PartitionName + '"
},
"partition": {
"name": "' + @PartitionName + '",
"dataView": "full",
"source": {
"type": "m",
"expression": [
"let",
" Source = #\"SQL/audex-analyse-dev-ssdw-rds c6lalk0xulcn eu-west-2 rds amazonaws com;audex-an\",",
" audexdw_fact_viewing_session_member = Source{[Schema=\"audexdw\",Item=\"fact_viewing_session_member\"]}[Data],",
" #\"Changed Type\" = Table.TransformColumnTypes(audexdw_fact_viewing_session_member,{{\"person_id\", type text}}),",
" #\"Filtered Rows\" = Table.SelectRows(#\"Changed Type\", each [calendar_id] = ' + CAST(@CalendarID AS NVARCHAR) + ')",
"in",
" #\"Filtered Rows\""
]
}
}
}
}';
-- Execute the TMSL script using SSMS or any other tool that supports TMSL execution
EXEC sp_execute_external_script @TMSL;
SET @CurrentDate = DATEADD(DAY, 1, @CurrentDate);
END
END
- Execute the Stored Procedure
You can execute the stored procedure to create the partitions. This will loop through each date and create a partition with the appropriate name and filter criteria.
EXEC CreateDailyPartitions;
Additional Considerations
- Performance: Ensure that your SSAS server can handle the number of partitions being created. Too many partitions can impact performance.
- Maintenance: Regularly review and maintain the partitions to ensure they are optimized and not causing unnecessary overhead.
- Error Handling: Add error handling in the stored procedure to manage any issues that may arise during the partition creation process.
References
I hope this helps you automate the process of building daily partitions in SSAS Tabular. If you have any further questions or need additional assistance, feel free to ask. Good luck with your project!
Best regards,
Jonathan
Your feedback is very important to us! If this answer resolved your query, please click 'YES'. This helps us continuously improve the quality and relevance of our solutions. Thank you for your cooperation!