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...
Follow these steps to calculate today's date using an attribute hierarchy:
Right-click on the Date table and select New Named Calculation.
Enter
Today
for Column Name and the following for the expression:case when convert(varchar(8), FullDateAlternateKey...