Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
amnadeem1991
Helper I
Helper I

Reverse Selection in Visuals (reverse slicer)

I have 2 visuals on my dashboard. One visual is a Line chart, showing Spend Values by Categories. The other visual is a slicer, showing list of all Categories (say, A B C D and E). On usual basis, when I select any categories (like A and B), the line chart shows spend related to those selected categories. However, my requirement is opposite to that. Means, when I select Category A and B in slicer, the line chart should show all the data except related to Category A and B . . . . The Reverse Selection!
Is there any DAX or Visual or Interaction available to enable this task?
1 ACCEPTED SOLUTION

OK @amnadeem1991, I believe I have it.. What I did was duplicate my disconnected table CategoryExcept as CategoryExcept1. This should also be a completely disconnected table (not connected to CategoryExcept or ExceptCategories in my model.

 

Then, create your second slicer based upon CategoryExcept, your original disconnected table. Edit interactions to not have this slicer filter the table that you have that you created with the original "Measures to Show". Now, create the following measure:

 

Measures to Show 1 = 
    VAR mytable1 = EXCEPT(ALL(CategoryExcept[Category]),VALUES(CategoryExcept[Category]))
    VAR mytable = EXCEPT(mytable1,VALUES(ExceptCategories[Category]))
    RETURN
IF(
    ISFILTERED(ExceptCategories[Category]),
    IF(HASONEVALUE(CategoryExcept1[Category]),
    SWITCH(VALUES(CategoryExcept1[Category]),
        "Consultancy",IF(CONTAINS(mytable,[Category],"Consultancy"),[ConsultancySum],BLANK()),
        "Fruit",IF(CONTAINS(mytable,[Category],"Fruit"),[FruitSum],BLANK()),
        "Hardware",IF(CONTAINS(mytable,[Category],"Hardware"),[HardwareSum],BLANK()),
        "Juices",IF(CONTAINS(mytable,[Category],"Juices"),[JuicesSum],BLANK()),
        "Office Supplies",IF(CONTAINS(mytable,[Category],"Office Supplies"),[OfficeSuppliesSum],BLANK()),
        "PPE",IF(CONTAINS(mytable,[Category],"PPE"),[PPESum],BLANK()),
        "Software",IF(CONTAINS(mytable,[Category],"Software"),[SoftwareSum],BLANK()),
        BLANK()
    ))
)

You should notice that this is exactly the same as the original "Measures to Show" measure (uses the same measures you previously created) except for the first two VAR lines and the references to CategoryExcept1 instead of CategoryExcept. Effectively, what those two VAR lines are doing are taking all of your category values, excluding the values selected in your first slicer and then excluding the values you selected in your second slicer. Create a table visualization with the Category from CategoryExcept1 and this new "Measures to Show 1" and you should have what you are looking for. In theory, you could essentially continue this technique ad infinitum.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

14 REPLIES 14
Greg_Deckler
Super User
Super User

Honestly, that's weird. Make sure slicer is mulit-select, make sure that Select All is turned all. Select all, uncheck A and B. Done.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Again stating my requirement, If I select category A and B in slicer, the line chart should show data related to Category C and D. Whatever is selected in slicer, line chart should show the rest of the data, and not the one related to selected items.

I'll have to study that solution and see if I can come up with a way to apply it to your situation. It appears similar to a disconnected table trick. Honestly though, if someone handed me a report that worked that way the first thing I would do is punch them. Then I would fire them and then I would punch them again for good measure. That just seems like an amazingly counter-intuitive way to design a report that way.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Your response on solution will be much appreciated.
And on you later honest comment, it all depends on the requirement of analysis. In my case, our requirement is to select some items, and then to carry forward balance items to next report.... then again select some more items from those balance items, and then again to carry forward the new balance items... So, reverse selection/filter is indeed necessary.

Given this Enter Data query:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI0UIrViVZyAjKNIExnsCiE7QIWhrBdgWxjEDsWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Category = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Value", Int64.Type}})
in
    #"Changed Type"

Create Measure:

 

 

ExceptSum = CALCULATE(SUM('Except'[Value]),EXCEPT(ALL('Except'[Category]),VALUES('Except'[Category])))

Use Category as slicer. Plot ExceptSum. Done. If you need a more specific solution, you will need to supply sample data.

 

 Don't blame me if you get punched though... 🙂


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Unfortunately, I was unable to interpret your syntax. When it comes to development/DAX, I am kind of new to power BI. Please access the sample file at following link: https://www.dropbox.com/s/0d0hwu90pk2qvo9/Table1.xlsx?dl=0.

Demo1.pngIt has 3 headers, "Category, NetValue and Year". Task is to get a list of left-over categories. Using reverse slicer, I would need to select any categories (say, Fruit and Juices), and another table (showing categories) should show the list of balance categories (other than Fruit and Juices). Similarly, once I select more categories out of balance categories using another slicer (say, hardware and software), another table should show the balance categories (all categories other than fruit, juice, hardware and software). You may refer to the attached image that shows the the target task.

OK, amazingly, this is actually possible. But, you are probably not going to like the solution all that much. I put your data into a table called ExceptCategories.

 

So, the first thing you do is you create a disconnected table (no relationships to anything) of all of your categories:

 

I called my CategoryExcept:

 

Category

Office Supplies
Consultancy
Fruit
Juices
PPE
Hardware
Software

 

Next, you create measures for each of your categories like this:

 

 

ConsultancySum = CALCULATE(SUM(ExceptCategories[NetValue]),FILTER(ALL(ExceptCategories),ExceptCategories[Category]="Consultancy"))

FruitSum = CALCULATE(SUM(ExceptCategories[NetValue]),FILTER(ALL(ExceptCategories),ExceptCategories[Category]="Fruit"))

HardwareSum = CALCULATE(SUM(ExceptCategories[NetValue]),FILTER(ALL(ExceptCategories),ExceptCategories[Category]="Hardware"))

JuicesSum = CALCULATE(SUM(ExceptCategories[NetValue]),FILTER(ALL(ExceptCategories),ExceptCategories[Category]="Juices"))

OfficeSuppliesSum = CALCULATE(SUM(ExceptCategories[NetValue]),FILTER(ALL(ExceptCategories),ExceptCategories[Category]="Office Supplies"))

PPESum = CALCULATE(SUM(ExceptCategories[NetValue]),FILTER(ALL(ExceptCategories),ExceptCategories[Category]="PPE"))

SoftwareSum = CALCULATE(SUM(ExceptCategories[NetValue]),FILTER(ALL(ExceptCategories),ExceptCategories[Category]="Software"))

Now, you create the following magical measure:

 

 

Measures to Show = 
    VAR mytable = EXCEPT(ALL(ExceptCategories[Category]),VALUES(ExceptCategories[Category]))
    RETURN
IF(
    ISFILTERED(ExceptCategories[Category]),
    IF(HASONEVALUE(CategoryExcept[Category]),
    SWITCH(VALUES(CategoryExcept[Category]),
        "Consultancy",IF(CONTAINS(mytable,[Category],"Consultancy"),[ConsultancySum],BLANK()),
        "Fruit",IF(CONTAINS(mytable,[Category],"Fruit"),[FruitSum],BLANK()),
        "Hardware",IF(CONTAINS(mytable,[Category],"Hardware"),[HardwareSum],BLANK()),
        "Juices",IF(CONTAINS(mytable,[Category],"Juices"),[JuicesSum],BLANK()),
        "Office Supplies",IF(CONTAINS(mytable,[Category],"Office Supplies"),[OfficeSuppliesSum],BLANK()),
        "PPE",IF(CONTAINS(mytable,[Category],"PPE"),[PPESum],BLANK()),
        "Software",IF(CONTAINS(mytable,[Category],"Software"),[SoftwareSum],BLANK()),
        BLANK()
    ))
)

Then, you create a Slicer based upon ExceptCategories[Category]. Then you create a table with CategoryExcept[Category] and [Measures to Show]

 

And it actually works, which is amazing.

 

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

The information you shared is greatly helpful, thank you. This works great when only one value is selected in slicer. But failing for multiple selection (e.g. "Consultancy" and "Fruit") with error "table value was returned by the expression when single value was expected". Can you please suggest how to address it?

@giramswa I think I solved this here:

Inverse Selector - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Great stuff, it really worked... Thanks a lot. However, either the solution is workable for 1 time selection of categories, or I am not able to make it usefull for more than 1 tables/slicers. I have uploaded the latest Excel and .pbix file on following dropbox link: https://www.dropbox.com/sh/omel37fmyevwfzd/AACmcZ227rD80ua2Rq2tqJPua?dl=0.  

 

Demo(1).pngDemo(2).pngI followed your syntax, created table (1) that simply shows overall categories. Then I created slicer (1) and table (2). When I select any categories (like, Office Supplies and PPE) from Slicer (1), the table (2) shows rest of the categories (all except Office Supplies and PPE) - That's great, and fulfills the fisrt part of requirement.... However, next to it, I need to have another slicer (2) and table (3). Once "Office Supplies and PPE" are selected from Slicer (1), the Table (2) and Slicer (2) both should show left-over categories (all except Office Supplies and PPE). Then, out of those left-over categories in Slicer (2), I need to select further categories (say, Consultancy and Hardware), then the table (3) should show only the categories selected in Slicer (2), and the table (4) should further drill down to show another list of overall balance categories (all except Office Supplies, PPE, Consultancy and Hardware). I hopw you understood the idea. Can you assist in reaching this schematic? Thank you. (If you wish to make changes in my .pbix file, please feel free to do so and share the updated file). Please also see the attached pictures to get better idea.

I'll see if I can find some time to take a look at this. This just seems like a ton of work to get to something that is done incredibily easily by just using select all and then unselecting the things you don't want. At that point, what you are asking for is absolutely trivial and will work without any code what-so-ever. I'm not getting the business case where selecting an item from a slicer is so vastly different than unselecting a value from a slicer.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

OK @amnadeem1991, I believe I have it.. What I did was duplicate my disconnected table CategoryExcept as CategoryExcept1. This should also be a completely disconnected table (not connected to CategoryExcept or ExceptCategories in my model.

 

Then, create your second slicer based upon CategoryExcept, your original disconnected table. Edit interactions to not have this slicer filter the table that you have that you created with the original "Measures to Show". Now, create the following measure:

 

Measures to Show 1 = 
    VAR mytable1 = EXCEPT(ALL(CategoryExcept[Category]),VALUES(CategoryExcept[Category]))
    VAR mytable = EXCEPT(mytable1,VALUES(ExceptCategories[Category]))
    RETURN
IF(
    ISFILTERED(ExceptCategories[Category]),
    IF(HASONEVALUE(CategoryExcept1[Category]),
    SWITCH(VALUES(CategoryExcept1[Category]),
        "Consultancy",IF(CONTAINS(mytable,[Category],"Consultancy"),[ConsultancySum],BLANK()),
        "Fruit",IF(CONTAINS(mytable,[Category],"Fruit"),[FruitSum],BLANK()),
        "Hardware",IF(CONTAINS(mytable,[Category],"Hardware"),[HardwareSum],BLANK()),
        "Juices",IF(CONTAINS(mytable,[Category],"Juices"),[JuicesSum],BLANK()),
        "Office Supplies",IF(CONTAINS(mytable,[Category],"Office Supplies"),[OfficeSuppliesSum],BLANK()),
        "PPE",IF(CONTAINS(mytable,[Category],"PPE"),[PPESum],BLANK()),
        "Software",IF(CONTAINS(mytable,[Category],"Software"),[SoftwareSum],BLANK()),
        BLANK()
    ))
)

You should notice that this is exactly the same as the original "Measures to Show" measure (uses the same measures you previously created) except for the first two VAR lines and the references to CategoryExcept1 instead of CategoryExcept. Effectively, what those two VAR lines are doing are taking all of your category values, excluding the values selected in your first slicer and then excluding the values you selected in your second slicer. Create a table visualization with the Category from CategoryExcept1 and this new "Measures to Show 1" and you should have what you are looking for. In theory, you could essentially continue this technique ad infinitum.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

HI @Greg_Deckler,

This approach is nice but it will work only for limited records. As in this case, categories are near about 10. What if records increases to 100. Then how am I supposed to create query for all of them? I have same requirement of reverse filtering where records are 'users' and slicer is 'date'.

 

Here is my query : https://community.powerbi.com/t5/Desktop/Non-Filtered-Data/m-p/482048#M14791

 

Thanks,

Piyush

I tried turning on each parameter, but does not work.
Actually, i followed the solution as per following post: http://community.powerbi.com/t5/Desktop/Slicer-reverse-selection-in-chart/m-p/96316#M40562.
But, it allows only single reverse selection.
Please can you share any syntax or demo example that can be used to make my case useful? My intention is to select items in slicer, and the line chart should show all the data except the selected items in slicer. Means, reverse filter.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.