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

Using 2 Slicers to Calculate/Display Variance

Hello,

 

I have a single visual where I would like users to be able to select two months via two separate slicers in order to calculate the difference in performance for each group's performance for the two months selected. See screenshot below.

For example, Group number 1 has values of 1.94 for May and 1.44 for April.  I want the math of 1.94 - 1.44 = 0.54 to be calculated. I would like the difference of 0.54 to be shown on the visual instead of the 1.94 for the first group. 

 

Data can be found here: https://www.dropbox.com/s/n3rzu68aolp8azo/05.16%20Forum%20Question.pbix?dl=0

The desired outcome is two slicers affecting one visual where a user can pick two months to see the variance among groups.

CoreyLearnsBI_0-1652711459790.png

 

 

Can this be done? How can this be done? I am a fairly new Power BI user, so I might need a more elaborate explanation/demonstration. I plan on using the visual for all 12 calendar months, but with only 2 slicers to enable users to see the variance between 2 months of data.

 

I tried something like this, but it sums all the groups' data together. I need each group's variance to be displayed individually on the visual, instead of one summation.

sumtable1 = CALCULATE(SUM(Table1[take]),ALLSELECTED(Table1[Month1]))
sumTable2 = CALCULATE(SUM(Table2[Take]),ALLSELECTED(Table2[Month2]))
look up the values = [sumtable1]-[sumTable2]

Monthly Variance (From Two Slicers).PNG

 

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

Hi @CoreyLearnsBI ,

 

I download your pbix file and check it. I think you create two slicers by same [Month/Year] column. We couldn't get two different values from one column. It is better for you to create an unrelated Month/Year table for slicer2.

Month/Year = 
VALUES('Data for SQL (MY22)'[Month/Year])

Then create a measure to achieve your goal.

Display Variance = 
VAR _sumtable1 =
    CALCULATE ( SUM ( 'Data for SQL (MY22)'[Metric 1] ) )
VAR _selectmonth =
    SELECTEDVALUE ( 'Month/Year'[Month/Year] )
VAR _sumtable2 =
    CALCULATE (
        SUM ( 'Data for SQL (MY22)'[Metric 1] ),
        FILTER (
            ALLEXCEPT (
                'Data for SQL (MY22)',
                'Data for SQL (MY22)'[Group],
                'Data for SQL (MY22)'[Market]
            ),
            'Data for SQL (MY22)'[Month/Year] = _selectmonth
        )
    )
RETURN
    _sumtable1 - _sumtable2

Result is as below.

RicoZhou_0-1652771892085.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

4 REPLIES 4
v-rzhou-msft
Community Support
Community Support

Hi @CoreyLearnsBI ,

 

I download your pbix file and check it. I think you create two slicers by same [Month/Year] column. We couldn't get two different values from one column. It is better for you to create an unrelated Month/Year table for slicer2.

Month/Year = 
VALUES('Data for SQL (MY22)'[Month/Year])

Then create a measure to achieve your goal.

Display Variance = 
VAR _sumtable1 =
    CALCULATE ( SUM ( 'Data for SQL (MY22)'[Metric 1] ) )
VAR _selectmonth =
    SELECTEDVALUE ( 'Month/Year'[Month/Year] )
VAR _sumtable2 =
    CALCULATE (
        SUM ( 'Data for SQL (MY22)'[Metric 1] ),
        FILTER (
            ALLEXCEPT (
                'Data for SQL (MY22)',
                'Data for SQL (MY22)'[Group],
                'Data for SQL (MY22)'[Market]
            ),
            'Data for SQL (MY22)'[Month/Year] = _selectmonth
        )
    )
RETURN
    _sumtable1 - _sumtable2

Result is as below.

RicoZhou_0-1652771892085.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.

 

Hey Rico, 

Thanks for taking the time to walk through this example with me! 

Do you mind me asking if there is a textbook/course you recommend for mastering DAX?

lbendlin
Super User
Super User

As long as you use disconnected tables for your slicers and measures for your result this will be straightforward.

 

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to assist you. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523 

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.