Skip to content

Total Sales, both before and after, a particular Date (even when date is dynamically selected)

>> Download the sample (Power BI)

This sample shows, dynamically, the Total Sales both before and after a particular date.

Day Number =
SELECTEDVALUE ( 'Number of Days'[Number of Days] )
Selected Date =
SELECTEDVALUE ( Selection_Date[Date] )
Total Sales =
SUMX ( Sales_Table, Sales_Table[Unit Price] * Sales_Table[Quantity] )
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 =
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 =
SELECTEDVALUE ( 'Number of Days'[Number of Days] )
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 )
)
Number of Days =
GENERATESERIES ( 0, 180, 1 )