How to get current date in MDX date range clause?

Jeevan Sandhu 5 Reputation points
2023-08-03T10:26:14.5366667+00:00

I have a MDX query that is pulling data from the cube. I require to add a date range condition so it is pulling data from 2019 onwards to the current date.

I have never worked with MDX before therefore used report builder.#

This is the query I have, but instead of null I want it to be upto current date:

SELECT 
	NON EMPTY { [Measures].[Premium LCL] } ON COLUMNS, 
	NON EMPTY { (
			[D_BU].[Business Unit Number].[Business Unit Number].ALLMEMBERS * 
			[D_TransactionDate].[Accounting Year].[Accounting Year].ALLMEMBERS *
		 	[D_TransactionDate].[Accounting Month Year].[Accounting Month Year].ALLMEMBERS * 
			[D_BU].[Region Name].[Region Name].ALLMEMBERS * 
			[D_BU].[Branch Name].[Branch Name].ALLMEMBERS *  
			[D_Industry_SIC].[SIC Level 3 Name].[SIC Level 3 Name].ALLMEMBERS 
			) } DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS 
FROM 
	( 
	 SELECT 
		( 
		 { [D_BU].[RegionName].&[UK - Underwriting]  
                   [D_BU].[RegionName].&[UK] } 
	        ) ON COLUMNS 
FROM 
       ( 
	SELECT 
		( 
		-{ [D_BU].[BranchName].&[Re Centre],
		   [D_BU].[BranchName].&[UK&Ireland] } 
		) ON COLUMNS 
FROM 
      ( 
	SELECT 
		( 
		   [D_TransactionDate].[Accounting Year].&[2019] : null 
		) ON COLUMNS 
FROM 
	[Model]
))) 
WHERE ( [D_BU].[RegionName].CurrentMember ) CELL PROPERTIES VALUE
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,338 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Olaf Helper 46,551 Reputation points
    2023-08-03T11:00:33.9966667+00:00

    but instead of null I want it to be upto current date:

    In a cube calculation / MDX queries you can use VBA = "Visual Basic for Applications", same as in Word/Excel and it's possible to use the complete Excel library.

    With that you can "calculate" a specific day, for example yesterday:

    CREATE STATIC SET CURRENTCUBE.[Yesterday]
    AS StrToSet('{[Calendar].[Hierachy].[Date].&[' + VBA!FORMAT(VBA!DATEADD("d", -1, VBA!NOW()), "yyyy-MM-dd") + 'T00:00:00]}')
    ,DISPLAY_FOLDER = 'Calendar Range';
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.