Forum Discussion
Need to add columns to table visual based on slicer selection
- 5 years ago
Hi Anonymous ,
If cannot using unpivot feature due to the size of your data source, you can extract the column name as a new table like this(supposing there has been a column that you must show it in the visual, otherwise it could not be supported currently unless usng unpivot)
In my sample, supposing the index column must be shown in the visual, the query could be like this:
let Source = Table.ColumnNames(#"Table"), #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Column Name"}}), #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Column Name", type text}}), #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Column Name] <> "Index")) in #"Filtered Rows"Create a measure like this:
A = SWITCH ( SELECTEDVALUE ( 'Column Name'[Column Name] ), "Column1", MAX ( 'Table'[Column1] ), "Column2", MAX ( 'Table'[Column2] ), "Column3", MAX ( 'Table'[Column3] ), "Column4", MAX ( 'Table'[Column4] ), "Column5", MAX ( 'Table'[Column5] ), "Column6", SUM ( 'Table'[Column6] ), "Column7", SUM ( 'Table'[Column7] ), "Column8", SUM ( 'Table'[Column8] ), "Column9", SUM ( 'Table'[Column9] ), "Column10", SUM ( 'Table'[Column10] ) )Use a Matrix visual not a table visual to show the result:
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
If cannot using unpivot feature due to the size of your data source, you can extract the column name as a new table like this(supposing there has been a column that you must show it in the visual, otherwise it could not be supported currently unless usng unpivot)
In my sample, supposing the index column must be shown in the visual, the query could be like this:
let
Source = Table.ColumnNames(#"Table"),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Column Name"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Column Name", type text}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Column Name] <> "Index"))
in
#"Filtered Rows"
Create a measure like this:
A =
SWITCH (
SELECTEDVALUE ( 'Column Name'[Column Name] ),
"Column1", MAX ( 'Table'[Column1] ),
"Column2", MAX ( 'Table'[Column2] ),
"Column3", MAX ( 'Table'[Column3] ),
"Column4", MAX ( 'Table'[Column4] ),
"Column5", MAX ( 'Table'[Column5] ),
"Column6", SUM ( 'Table'[Column6] ),
"Column7", SUM ( 'Table'[Column7] ),
"Column8", SUM ( 'Table'[Column8] ),
"Column9", SUM ( 'Table'[Column9] ),
"Column10", SUM ( 'Table'[Column10] )
)
Use a Matrix visual not a table visual to show the result:
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
I am trying to implement your solution on a similar problemwhere I need to display data in a cost sheet based on Fiscal year(s) selected in the slicer. All attempts to implement have failed and I cannot use the UNPIVOT method as it makes the data unreadable.