Current and prior periods

A common requirement of date intelligence metrics is to compare the YTD total for a measure versus the equivalent time period of the prior year. For example, on November 14, 2017, the visual would compare January through October of 2017 versus January through October of 2016. Without any external filtering, however, a standard YTD measure would include the 14 days of November in 2017 and would capture the entire year of 2016 if the year 2016 was in the filter context. To deliver equivalent or apples to apples comparisons of equal time periods, the filter context of measures can be further customized. 

The following measures retrieve the year-to-date net sales through the prior calendar month and prior calendar week. For example, throughout the month of November, the YTD Last Month measure would, at most, only retrieve the net sales through the month of October. Likewise, the YTD Last Week measure would, at most, only include the net sales through the end of the prior week of the year (45):

Prior Calendar Month Number = 
VAR CurrentDay = TODAY()
RETURN
IF (
LOOKUPVALUE('Date'[Calendar Month Number],'Date'[Date],CurrentDay) = 1,12,
LOOKUPVALUE('Date'[Calendar Month Number],'Date'[Date],CurrentDay)-1
)
Prior Calendar Week Number =
VAR CurrentDay = TODAY()
RETURN
IF(
LOOKUPVALUE('Date'[Calendar Week Number in Year],'Date'[Date],CurrentDay) = 1, CALCULATE(MAX('Date'[Calendar Week Number in Year]),FILTER(ALL('Date'),'Date'[Calendar Year] = MAX('Date'[Calendar Year]) - 1)),
LOOKUPVALUE('Date'[Calendar Week Number in Year],'Date'[Date],CurrentDay)-1)

Internet Net Sales (YTD Last Month) =
IF([Prior Calendar Month Number] <> 12,
CALCULATE([Internet Net Sales], FILTER(ALL('Date'),'Date'[Calendar Year] = MAX('Date'[Calendar Year]) &&
'Date'[Date] <= MAX('Date'[Date]) && 'Date'[Calendar Month Number] <= [Prior Calendar Month Number])),
CALCULATE([Internet Net Sales], FILTER(ALL('Date'), 'Date'[Calendar Year] = MAX('Date'[Calendar Year])-1 && 'Date'[Date] <= MAX('Date'[Date]) && 'Date'[Calendar Month Number] <= [Prior Calendar Month Number])))

Internet Net Sales (YTD Last Week) =
VAR CurrentWeek = LOOKUPVALUE('Date'[Calendar Week Number in Year],'Date'[Date],TODAY())
RETURN
IF(CurrentWeek <> 1,
CALCULATE([Internet Net Sales], FILTER(ALL('Date'),'Date'[Calendar Year] = MAX('Date'[Calendar Year]) &&
'Date'[Date] <= MAX('Date'[Date]) && 'Date'[Calendar Week Number in Year] <= [Prior Calendar Week Number])),
CALCULATE([Internet Net Sales], FILTER(ALL('Date'),'Date'[Calendar Year] = MAX('Date'[Calendar Year])-1 && 'Date'[Date] <= MAX('Date'[Date]) && 'Date'[Calendar Week Number in Year] <= [Prior Calendar Week Number])))

For any prior calendar year in the filter context, the (YTD Last Month) measure would only include January through October for this given year. Likewise, the (YTD Last Week) measure would only include weeks 1 through 45 of the given year. By embedding this dynamic filtering logic, it's possible to use these measures in report visuals without applying any additional filters.

The TODAY() function combined with the LOOKUPVALUE() function makes it possible to retrieve values at query time relative to the current date. In the previous example, the month and week number columns of the current year (for example, October = 10) are queried via LOOKUPVALUE() based on the current date. With these values retrieved, subtracting one from the results provides the value associated with the prior month and prior week, respectively. These measures are then referenced in the FILTER() function of their respective year-to-date measures.

Similar to this simple example, dynamically computed dates and other values make it possible to create measures for the current date and yesterday:

Internet Net Sales (Today) = CALCULATE([Internet Net Sales],
FILTER(ALL('Date'),'Date'[Date] = TODAY()))

Internet Net Sales (Yesterday)
= CALCULATE([Internet Net Sales],
FILTER(ALL('Date'),'Date'[Date] = TODAY()-1))

Along with the date intelligence metrics described in the following section, a rich set of date-based metrics give users of Power BI reports and dashboards visibility for both short and long-term results.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.27.178