>> Download the sample (Power BI)
This sample shows, dynamically, the Total Sales both before and after a particular date.
Dashboard - Snippet
Section titled “Dashboard - Snippet”
Data Model - Snippet
Section titled “Data Model - Snippet”
Measures - Sales & Calendar Time
Section titled “Measures - Sales & Calendar Time”Day Number
Section titled “Day Number”Day Number =SELECTEDVALUE ( 'Number of Days'[Number of Days] )Selected Date
Section titled “Selected Date”Selected Date =SELECTEDVALUE ( Selection_Date[Date] )Total Sales
Section titled “Total Sales”Total Sales =SUMX ( Sales_Table, Sales_Table[Unit Price] * Sales_Table[Quantity] )Total Sales after selected Date
Section titled “Total Sales after selected Date”Total Sales after selected Date =VAR SelectedDate = CALCULATE ( MAX ( Selection_Date[Date] ), ALL ( Calendar_Table ) )RETURN IF ( ISFILTERED ( Calendar_Table[Date].[Day] ), IF ( AND ( MAX ( Calendar_Table[Date] ) > SelectedDate, MAX ( Calendar_Table[Date] ) <= SelectedDate + [Day Number] ), [Total Sales], BLANK () ), BLANK () )Total Sales before selected Date
Section titled “Total Sales before selected Date”Total Sales before selected Date =VAR SelectedDate = CALCULATE ( MAX ( Selection_Date[Date] ), ALL ( Calendar_Table ) )RETURN IF ( ISFILTERED ( Calendar_Table[Date].[Day] ), IF ( AND ( MAX ( Calendar_Table[Date] ) > SelectedDate - [Day Number], MAX ( Calendar_Table[Date] ) <= SelectedDate ), [Total Sales], BLANK () ), BLANK () )Number of Days Value
Section titled “Number of Days Value”Number of Days Value =SELECTEDVALUE ( 'Number of Days'[Number of Days] )Tables
Section titled “Tables”Calendar_Table
Section titled “Calendar_Table”Calendar_Table =GENERATE ( CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2019, 12, 31 ) ), VAR currentDay = [Date] VAR Day = DAY ( currentDay ) VAR Month = MONTH ( currentDay ) VAR Year = YEAR ( currentDay ) RETURN ROW ( "Day", day, "Month", month, "Year", year ))Calculated Columns
Section titled “Calculated Columns”Number of Days
Section titled “Number of Days”Number of Days =GENERATESERIES ( 0, 180, 1 )