Skip to content

Correct Totals with Iterators

>> Download the sample (Power BI)

This sample shows the minimum of this year’s and last year’s sales.

Min Revenue (Correct Total) =
SUMX (
SUMMARIZE ( Customer_Table, Customer_Table[Customer] ),
MIN ( [Total Revenue], [Total Revenue LY] )
)
Min Revenue (Incorrect Total) =
MIN ( [Total Revenue], [Total Revenue LY] )
Total Revenue =
SUMX ( Sales_Table, Sales_Table[Quantity] * Sales_Table[Unit Price] )
Total Revenue LY =
CALCULATE ( [Total Revenue], DATEADD ( Calendar_Table[Date], -1, YEAR ) )
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 )
)