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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Jebilaya
Helper III
Helper III

SAMEPERIODLASTYEAR contiguous selection issue

I have a date master table against which my SAMEPERIODLASTYEAR DAX works fine however I have another report so the user can select a rolling 12 month date range (Date Range Selection) which has a 1 - Many relationship back to the date master table.

 

However my sameperiod last year formula does not work when this is presented on visuals.  Any ideas?

 

Relationships as below:

 

Jebilaya_0-1707481280395.png

Works fine when individual year from the date master table is selected

 

Jebilaya_1-1707481370688.png

Does not work if rolling 12 months from date range selection is selected

 

Jebilaya_2-1707481426633.png

 

Dax for LY measure is 

NMR LY = calculate([NMR], SAMEPERIODLASTYEAR('Dim Date Master'[Date]))
Dax for Date range selection is 
Date Range Selection =

Var enddate = max('Fact Safety Stats'[W/C Date])
Var startdate = enddate - 362

Var result =
union(
ADDCOLUMNS(calendar(startdate, enddate), "Selection", "Rolling 12 Months", "Order", "1"),
ADDCOLUMNS(calendar(startdate - 396, startdate - 1), "Selection", "Prior Year", "Order", "2"))

 return
 result
1 REPLY 1
lbendlin
Super User
Super User

Please clarify what "doesn't work"  means.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.