Skip to content

Highlighting the Last period in a DAX Visualisation

>> Download the sample (Power BI)

This sample highlights the last (or current) period in a DAX visualisation, for example when showing sales for each month in a year.

Last Sale Period =
VAR LastSale =
CALCULATE ( MAX ( Sales_Table[Date] ), ALLSELECTED ( Sales_Table ) )
RETURN
IF (
DATE ( YEAR ( LastSale ), MONTH ( LastSale ), 1 )
= DATE ( YEAR ( MAX ( Calendar_Table[Date] ) ), MONTH ( MAX ( Calendar_Table[Date] ) ), 1 ),
1,
0
)
Last Sales =
CALCULATE ( MAX ( Sales_Table[Date] ), ALL ( Calendar_Table ) )
SUMX Total Sales =
SUMX ( Sales_Table, Sales_Table[Quantity] * Sales_Table[Unit Price] )
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 )
)