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
mariebel
Frequent Visitor

DAX: working with comparison dates for last year figures

Hi all, 

 

Once again I find myself stuck with DAX. The below is something I might otherwise fix with a for loop, but with DAX I am just not sure how to fix it. 

 

What I would like to do is calculate last years sales, pretty simple you would say. However, in our company we work with comparison dates. So the 20th of april 2020 might be compared to the 19th of April of 2019. So simply using sameperiodlastyear will not work. 

 

To complicate matters further, in my reports i use a period selector, which allows users to select a period (i.e. last month, current month, current year, yesterday etc) and these periods correspond to a number of dates. 

 

A very simplified version of the current data model is this, where the dark lines are active relationships and the light line is an inactive one. 

datamodelsimplified.PNG

So I'd like to select a period from the PeriodSelector and get the sales figure from the corresponding previous year dates (determined by the dimDateComp). 

 

I hope this makes sense and many thanks in advance for your help. 

1 REPLY 1
Greg_Deckler
Super User
Super User

See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.