Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I regularly use SAMEPERIODLASTYEAR with CALCULATE, but I never quite understood why it works. Going by the documentation, SAMEPERIODLASTYEAR appears to return a column of dates. But how is a column of dates a valid input for the <filter> argument of CALCULATE?
CALCULATE(SUM(ResellerSales_USD[SalesAmount_USD]), SAMEPERIODLASTYEAR(DateTime[DateKey]))
SAMEPERIODLASTYEAR() This is a shortcut function that is just a wrapper to DATEADD(). It is 100% equivalent to DATEADD() with “-1, Year” as the last two arguments:
SAMEPERIODLASTYEAR ( Calendar[Date] ) Is exactly the same as: DATEADD ( Calendar[Date], -1, YEAR )
CALCULATE(SUM(ResellerSales_USD[SalesAmount_USD]), SAMEPERIODLASTYEAR(DateTime[DateKey]))=
CALCULATE(SUM(ResellerSales_USD[SalesAmount_USD]), DATEADD ( Calendar[Date], -1, YEAR )))
Cool, but how does that answer my question?
All filter expressions in CALCULATE are tables, and SAMEPERIODLASTYEAR (like the other Time Intelligence functions) return a table with a single column of dates.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
And how does a single column of dates serve as a filter to my original table?
It makes sense that something like this works:
CALCULATE(SUM(tbl[Sales]), tbl[Country]="US")
But I don't understand why the following would work:
CALCULATE(SUM(tbl[Sales]), {2021-04-01, 2021-04-02, 2021-04-03})
(using pseudo code for the second argument to represent a column of dates)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
97 | |
75 | |
63 | |
62 |
User | Count |
---|---|
135 | |
105 | |
104 | |
80 | |
65 |