Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
DanielM16
Frequent Visitor

Why can SAMEPERIODLASTYEAR be used as filter for e.g. CALCULATE?

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]))

 

Documentation SAMEPERIODLASTYEAR

Documentation CALCULATE

4 REPLIES 4
Singaravelu_R
Resolver III
Resolver III

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?

mahoneypat
Employee
Employee

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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI 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)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.