Forum Discussion
Reverse Selection in Visuals (reverse slicer)
- 8 years ago
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.
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... :)
- amnadeem19918 years agoHelper I
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.
It 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.
- Greg_Deckler8 years agoCommunity Champion
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.
- amnadeem19918 years agoHelper I
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.
I 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.