Calculating today's date using an attribute hierarchy

The third way to calculate today's date is by using an attribute hierarchy. This is potentially the best way.

Instead of all the complexity with sets, strings, and other things in the previous two recipes, here we simply add a new column to the Date table and have the ETL maintain a flag for today's date. Then we slice by that attribute instead of using the Now() function in MDX. Plus, we don't have to wait to switch to tomorrow in MDX queries until the ETL completes and the cube is processed.

Getting ready

Open the Adventure Works DW 2016 solution in SSDT. Double-click on the Adventure Works DW data source view. Locate the Date dimension in the left Tables pane and click on it.

How to do it... ...

Get MDX with Microsoft SQL Server 2016 Analysis Services Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.