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
wbhite
Helper I
Helper I

How to get variance based on two date slicers

Hello all,

I have a report where I need to show a variance based on selections in two date slicers.  See screenshot.  I have a single fact table connected to a date table.  That single date table is used to populate both slicers, and those slicers interact visually with each table based on the selection.  For the "Variance" measure, I've tried all manner of things based on search results, but none seem to pinpoint my exact (and hopefully simple) need here.  I won't muddy the waters by showing what I've already tried.

 

In the sample below, the expected result should be 0.03.  Can anyone point me in the right direction here?  Thanks in advance!

 

PBIsample.png

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

Hi @wbhite ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

Fact table:vtangjiemsft_0-1685584568237.png

Calendar table:

CALENDAR = CALENDAR(DATE(2023,1,1),DATE(2023,12,31))

(2) We can create a table and a measure. 

CALENDAR Table2 = VALUES('CALENDAR'[Date #1])

vtangjiemsft_1-1685584655436.png

Material cost = 
var _a=CALCULATE(MAX('Fact Table'[total material cost]),FILTER(ALL('Fact Table'),'Fact Table'[date]=SELECTEDVALUE('CALENDAR'[Date #1])))
var _b=CALCULATE(MAX('Fact Table'[total material cost]),FILTER(ALL('Fact Table'),'Fact Table'[date]=SELECTEDVALUE('CALENDAR Table2'[Date #2])))
return _b-_a

(3) Then the result is as follows.

vtangjiemsft_2-1685584721340.png

Best Regards,

Neeko Tang

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
Ashish_Mathur
Super User
Super User

Hi,

I cannot understand your requirement.  Why in the first place do you have 2 date slicers?  Do you want to compare the cost of 2 products between a week of each other?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-tangjie-msft
Community Support
Community Support

Hi @wbhite ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

Fact table:vtangjiemsft_0-1685584568237.png

Calendar table:

CALENDAR = CALENDAR(DATE(2023,1,1),DATE(2023,12,31))

(2) We can create a table and a measure. 

CALENDAR Table2 = VALUES('CALENDAR'[Date #1])

vtangjiemsft_1-1685584655436.png

Material cost = 
var _a=CALCULATE(MAX('Fact Table'[total material cost]),FILTER(ALL('Fact Table'),'Fact Table'[date]=SELECTEDVALUE('CALENDAR'[Date #1])))
var _b=CALCULATE(MAX('Fact Table'[total material cost]),FILTER(ALL('Fact Table'),'Fact Table'[date]=SELECTEDVALUE('CALENDAR Table2'[Date #2])))
return _b-_a

(3) Then the result is as follows.

vtangjiemsft_2-1685584721340.png

Best Regards,

Neeko Tang

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

This is great, thanks so much!

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.