cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gmiro767
New Member

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 @Gmiro767 ,

 

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 @Gmiro767 ,

 

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

Genious!

Thanks!

Ashish_Mathur
Super User III
Super User III

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

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.



Has this post solved your problem? Please mark it as a 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. ?


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

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
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors