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
MrUrban07
New Member

DAX comparing two periods using slicers

Hi All, 

I am struggeling to do a simple period over period comparison based on the below example. I want to use two slicers: 1) called current priod where I can select a date, and once slicer for previous period where I want to select another date to compare the amount. 

I have listed the data and the DM for reference. 

Many thanks.

 

MrUrban07_0-1689249631026.png

 

MrUrban07_1-1689249663964.png

 

 

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

Hi @MrUrban07 ,

 

I suggest you to create measures as below.

Previous Period = SELECTEDVALUE(previous_dt[Date])
Current Period = SELECTEDVALUE(Trial3[Date])
Current Amount = IF(ISFILTERED(Trial3[Date]),CALCULATE(SUM(Trial3[Amount])))
Previous Amount = CALCULATE(SUM(Trial3[Amount]),FILTER(ALL(Trial3),Trial3[Date] = [Previous Period]))
Diff = [Current Amount] - [Previous Amount]

Result is as below.

vrzhoumsft_0-1689581185080.png

You can also create a measure to filter previous period slicer to only show dates before current period.

Only Show Previous = 
IF(MAX(previous_dt[Date]) < [Current Period],1,0)

Add this measure into visual level filter of the slicer and set it to show items when value =1.

vrzhoumsft_1-1689581253838.png

vrzhoumsft_2-1689581265753.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @MrUrban07 ,

 

I suggest you to create measures as below.

Previous Period = SELECTEDVALUE(previous_dt[Date])
Current Period = SELECTEDVALUE(Trial3[Date])
Current Amount = IF(ISFILTERED(Trial3[Date]),CALCULATE(SUM(Trial3[Amount])))
Previous Amount = CALCULATE(SUM(Trial3[Amount]),FILTER(ALL(Trial3),Trial3[Date] = [Previous Period]))
Diff = [Current Amount] - [Previous Amount]

Result is as below.

vrzhoumsft_0-1689581185080.png

You can also create a measure to filter previous period slicer to only show dates before current period.

Only Show Previous = 
IF(MAX(previous_dt[Date]) < [Current Period],1,0)

Add this measure into visual level filter of the slicer and set it to show items when value =1.

vrzhoumsft_1-1689581253838.png

vrzhoumsft_2-1689581265753.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot).
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.

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

OwenAuger
Super User
Super User

Hi @MrUrban07 

I would recommend the method in this article on DAX Patterns:

https://www.daxpatterns.com/comparing-different-time-periods/

Under this method, you set up two date tables: 'Date' and 'Comparison Date' with relationships as described in the article. 

Then you can write measures similar to [Comparison Sales Amount].

 

regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

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.

Top Solution Authors