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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Gerbil
Helper I
Helper I

Matrix Values from Different Columns in Data Source?

Let's say I have a data source that looks like this:

IDABCDEFGHI
1abcdefghi
2abcdefghi
3abcdefghi
4abcdefghi
5abcdefghi

 

I'd like to make a table like so:

 Col1Col2Col3
Row1abc
Row2def
Row3ghi
 sum(col1)sum(col2)sum(col3)

 

Where I can put in a custom column header and row header, as well as get totals of each column. This table will be filtered with a slicer to a specific ID, so it will display all the values associated with that ID.

 

Is this possible?

1 ACCEPTED SOLUTION

yes, that can be done as well.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUoE4iQgTgbiFCBOBeI0IE4H4gwgzlSK1YlWMiJapTHRKk2IVmlKnMpYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, A = _t, B = _t, C = _t, D = _t, E = _t, F = _t, G = _t, H = _t, I = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Category", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Row", 1, 1, Int64.Type),
    #"Replaced Value" = Table.ReplaceValue(#"Added Index",each [Row],each let n=Int64.From(Number.Mod([Row]+1,9)/3) in if n=0 then 3 else n,Replacer.ReplaceValue,{"Row"})
in
    #"Replaced Value"

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

That's a standard "Unpivot in groups"  pattern.  What have you tried and where are you stuck?

I looked into unpivoting and it looks like a solution I can use. But can I change the query so that the table looks like this:

 

IDCategoryRowValue
1A1a
1B1b
1C1c
1D2d
1E2e
1F2f
1G3g
1H3h
1I3i

 

 

i.e. have two clauses for the category

yes, that can be done as well.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUUoE4iQgTgbiFCBOBeI0IE4H4gwgzlSK1YlWMiJapTHRKk2IVmlKnMpYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, A = _t, B = _t, C = _t, D = _t, E = _t, F = _t, G = _t, H = _t, I = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID"}, "Category", "Value"),
    #"Added Index" = Table.AddIndexColumn(#"Unpivoted Other Columns", "Row", 1, 1, Int64.Type),
    #"Replaced Value" = Table.ReplaceValue(#"Added Index",each [Row],each let n=Int64.From(Number.Mod([Row]+1,9)/3) in if n=0 then 3 else n,Replacer.ReplaceValue,{"Row"})
in
    #"Replaced Value"

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.