Forum Discussion
Slicer on column
I would like to have a slicer that would sum columns based on the selected column names, whether A1, A2 or A3 (with multiple selections allowed). As an example I have a table below with A1, A2 and A3 columns. The expected slicer would have choices of A1,A2 and A3. How can I add slicer on columns itself instead of its values?
As an example, I would like to plot A1 sum vs ID or A1+A2 sum vs ID based on selecting A1,A2 or A3 or combination of two or more in slicer or something allowing equivalent functionality.
Thanks
ID A1 A2 A3
| 1 | 51 | 57 | 50 |
| 2 | 99 | 23 | 93 |
| 3 | 92 | 28 | 11 |
| 4 | 13 | 43 | 81 |
| 5 | 98 | 21 | 47 |
| 1 | 31 | 57 | 98 |
| 2 | 25 | 11 | 28 |
| 3 | 98 | 61 | 88 |
| 4 | 26 | 85 | 38 |
| 5 | 29 | 89 | 90 |
Hi Ash187
Please kindly check whether you'd like to get below results:
1. here's the source data Table (3):
2. Add below M code to unpivot the columns:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY67EcAgDEN3cU0RbD5mFi77rxE/c6HRCUlI3luqFOkJE3jkLVs06FoBajBLMSmOekCtKTYoTgP8iJ0kIaW4zRShdofC/oe0n7osvkN8H4jud0gHb+Lmd0i504EVx78f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, A1 = _t, A2 = _t, A3 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"A1", Int64.Type}, {"A2", Int64.Type}, {"A3", Int64.Type}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value") in #"Unpivoted Columns"3. Then add the calculated table:
Table 2 = CALCULATETABLE(ALLSELECTED('Table (3)'),FILTER('Table (3)',[Attribute]="ID"))4. Add the measure to generate the results:
Measure 4 = var a = SUMX('Table (3)',[Value]) var b = SUMX('Table 2',[Value]) Return a-b
1 Reply
- v-diye-msftCommunity Support
Hi Ash187
Please kindly check whether you'd like to get below results:
1. here's the source data Table (3):
2. Add below M code to unpivot the columns:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PY67EcAgDEN3cU0RbD5mFi77rxE/c6HRCUlI3luqFOkJE3jkLVs06FoBajBLMSmOekCtKTYoTgP8iJ0kIaW4zRShdofC/oe0n7osvkN8H4jud0gHb+Lmd0i504EVx78f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, A1 = _t, A2 = _t, A3 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"A1", Int64.Type}, {"A2", Int64.Type}, {"A3", Int64.Type}}), #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value") in #"Unpivoted Columns"3. Then add the calculated table:
Table 2 = CALCULATETABLE(ALLSELECTED('Table (3)'),FILTER('Table (3)',[Attribute]="ID"))4. Add the measure to generate the results:
Measure 4 = var a = SUMX('Table (3)',[Value]) var b = SUMX('Table 2',[Value]) Return a-b