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
id013
Helper V
Helper V

Question about comparing data from 2 time periods

Hi,

 

I want to create a dashboard that compares 2 sets of dates, this year and last year. So I have a fact_volumes table that has volume data for the last 2 years (Jan 1 2019 to present) and it is linked to a date dimension table that has the same dates (Jan 1 2019 to Present).

 

The idea being that I select a time period (ex. Jan 1 2020 - March 31 2020) and I will be able to see volumes for the time period I've selcted Jan 1 2020 - Mar 31 2020 as well as the volumes for the same period of the previous years so Jan 1 2019 - Mar 31 2019. 

 

I know I can create the measures using the sameperiodlastyear function, the wrinkle I'm running into is that I only want the user to ony be able to select from a date range of this year. So the date slicer they see will only show the date range of Jan 1 2020 - Present Date. I've tried setting a filter on the date slicer to only show this years dates and it works fine as long as the date slicer is actively filtering dates, the problem is if you clear the filtering even though the date slicer shows this years dates, the volume measures are showing me the volumes for the whole 2 year period that is in my data set? 

 

Is there a better way to do this?

 

Thanks

1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @id013 ,

 

You could use page level filter and create measures as below.

this year = CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[date]>=MIN('Table'[date])&&'Table'[date]<=MAX('Table'[date])))

previous year = CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[date]>=EDATE(MIN('Table'[date]),-12)&&'Table'[date]<=EDATE(MAX('Table'[date]),-12)))

3.PNG2.PNG1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @id013 ,

 

You could use page level filter and create measures as below.

this year = CALCULATE(SUM('Table'[value]),FILTER('Table','Table'[date]>=MIN('Table'[date])&&'Table'[date]<=MAX('Table'[date])))

previous year = CALCULATE(SUM('Table'[value]),FILTER(ALL('Table'),'Table'[date]>=EDATE(MIN('Table'[date]),-12)&&'Table'[date]<=EDATE(MAX('Table'[date]),-12)))

3.PNG2.PNG1.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Thanks to everyone this was very helpful. I was able to accomplish what I needed by tweaking the logic in the measures like everyone suggested. 

Greg_Deckler
Super User
Super User

@id013 - Seems like you would have to build that filter into your measures. 

 

Otherwise, Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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.