Forum Discussion
right to left matrix
- 4 years ago
Well this isn't perfect, but it's the closest I have come.
1) In Power Query, create the layout of the matrix using:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdCxCoAwDATQf8ncweYi6OwnOJYiFcRREB38e6GDFMI5JnkcR1ISlSBTubb9OJ+4zPf6De1BckgCRtXRnlE4OjYbZQW00oFRdTR2zOI3FqwBKjVG1VEwCkcjo+Zo+y1jXU1yfgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Amount = _t, #"Sub-Category" = _t, Category = _t]), OrignalTable = Table.TransformColumnTypes(Source,{{"Amount", Int64.Type}, {"Sub-Category", type text}, {"Category", type text}}), #"Removed Other Columns" = Table.SelectColumns(OrignalTable,{"Category"}), #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"), #"Added Index" = Table.AddIndexColumn(#"Removed Duplicates", "Index", 1, 1, Int64.Type), CatIndex = Table.RenameColumns(#"Added Index",{{"Index", "CatIndex"}}), #"Merged Queries" = Table.NestedJoin(CatIndex, {"Category"}, OrignalTable, {"Category"}, "CatIndex.1", JoinKind.LeftOuter), #"Expanded CatIndex.1" = Table.ExpandTableColumn(#"Merged Queries", "CatIndex.1", {"Sub-Category"}, {"Sub-Category"}), #"Added Index1" = Table.AddIndexColumn(#"Expanded CatIndex.1", "Index", 1, 1, Int64.Type), #"Added Custom" = Table.AddColumn(#"Added Index1", "Custom", each [CatIndex] + [Index]/1000), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}), SubCatIndex = Table.RenameColumns(#"Removed Columns",{{"Custom", "SubCatIndex"}}), #"Removed Other Columns1" = Table.SelectColumns(SubCatIndex,{"Sub-Category", "SubCatIndex"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns1",{{"SubCatIndex", "CatIndex"}, {"Sub-Category", "Category"}}), #"Appended Query" = Table.Combine({#"Renamed Columns", #"CatIndex"}), #"Sorted Rows" = Table.Sort(#"Appended Query",{{"CatIndex", Order.Ascending}}) in #"Sorted Rows"which gets you
Create an active relationship between Matrix Category and the orginal table Category. Create an inactive relationship between Matrix Category and the original table SubCategory.
Then these measures:
Sum Value = SUM(OrigTable[Amount])Amount = VAR SubCat = CALCULATE ( [Sum Value], USERELATIONSHIP ( 'Matrix Structure'[Category], OrigTable[Sub-Category] ) ) RETURN IF ( ISINSCOPE ( 'Matrix Structure'[Category] ), [Sum Value] + SubCat, "Total " & FORMAT ( DIVIDE ( [Sum Value] + SubCat, 2 ), "#,##0" ) )Create a table visual with the field from the matrix table & the [Amount] measure, add conditional formatting and you get:
I've attached the sample PBIX file
Hi
To the right it's how the data is set in the table,
To the left is how I want to show it - Exactly how it's shown in a matrix, only right to left.
Thank you
- v-kelly-msft4 years ago
Community Support
Hi pbiuser1234 ,
Put category and subcategory to the Rows field and you will see:
Check my .pbix file attached.
Best Regards,
KellyDid I answer your question? Mark my reply as a solution!
- pbiuser12344 years ago
Helper I
Hi,
I need the "amount" column on the left, not right.
Exacty as shown in the example I attached.
Thanks