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
Anonymous
Not applicable

Conditional Filtering

Hey Everyone,

 

I'm pretty new to Power BI Desktop and I'd aprreciate your help.

I created a simple bar chart with months and sales. I also created a slicer based on months. I'm trying to make this scenario happen:

If I choose "October" in the slicer I want the bar chart to shoe me only "July","August","September" and "October".

If I choose "June" in the slicer I want the bar chart to shoe me only "March","April","May" and "June". 

Otherwise, the bar chart will show the value I chose in the slicer.

 

Any ideas how should I make it happen?

 

Thanks!

 

 

 

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

Hi @Anonymous ,

 

First you need to create a separate table for slicer filtering.

image.png

 

Then try the following formula to create measure:

Measure = 
var MonthNo = SELECTEDVALUE('Slicer Table'[month_no])
var _6_10 = 
    CALCULATE(
        SUM('Table'[Sales]),
        FILTER(
            'Table',
            'Table'[Month_No] in { MonthNo, MonthNo-1, MonthNo-2, MonthNo-3 }
        )
    )
var other = 
    CALCULATE(
        SUM('Table'[Sales]),
        'Table'[Month_No] = MonthNo
    )
return 
    SWITCH(
        MonthNo, 
        10, _6_10, 
        6,_6_10,
        BLANK(), SUM('Table'[Sales]),
        other
    )

 

image.pngimage.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

5 REPLIES 5
v-kkf-msft
Community Support
Community Support

Hi @Anonymous ,

 

First you need to create a separate table for slicer filtering.

image.png

 

Then try the following formula to create measure:

Measure = 
var MonthNo = SELECTEDVALUE('Slicer Table'[month_no])
var _6_10 = 
    CALCULATE(
        SUM('Table'[Sales]),
        FILTER(
            'Table',
            'Table'[Month_No] in { MonthNo, MonthNo-1, MonthNo-2, MonthNo-3 }
        )
    )
var other = 
    CALCULATE(
        SUM('Table'[Sales]),
        'Table'[Month_No] = MonthNo
    )
return 
    SWITCH(
        MonthNo, 
        10, _6_10, 
        6,_6_10,
        BLANK(), SUM('Table'[Sales]),
        other
    )

 

image.pngimage.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

Anonymous
Not applicable

Genious!

Thanks!

Ashish_Mathur
Super User
Super User

Hi,

Refer to my post here - Flex a Pivot Table to show data for x months ended a certain user defined month.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AllisonKennedy
Super User
Super User

So if you choose "May" you only want to see May? 

 

You'll need to set the slicer on an unrelated table and then can use DAX to do the filtering. A SWITCH statement would work, otherwise you could use a relationship and a mapping table, but that might get more complex.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Yes, if I choose May I would like to see only May.

Can you please demonstrate for me how it actually works ?

Much thanks!

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.