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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Any way to expand out columns Matrix into unique combinations of each possible value

In the SQL database I am using I have a bunch of factories, each of these factories will have a number of data entries representing their outputs/inputs. These are represented by three columns: Activity, Product, and Volume. I want to have the PowerBI Matrix expand out the Activity and Product table to instead have one column per combination with the volumes for all entries from that factory in a given month being summed in it's respective column.

e.g. if the columns contain the following Activity: (A, B, C, D) and Product (1, 2, 3) my specific then I would want to have 12 columns in the matrix A1, A2, A3, B1, ..., D2, D3. If my factory had 3 different volumes in the month reported for A3 then they would all get summed into the A3 column.

I haven't been able to find a way to expand out these columns as such, and am hoping I may be able to get some advice.

 

Here is some example data

image.png


expected Result (approximately) Something like this, but obviously in a PowerBI Matrix

 

ExP4d.png

 

I cannot give official data that I will be using for the project due to some confidential information, but this is a quite accurate to the overall goal. The real project has more than just 2 activities and 3 products

1 ACCEPTED SOLUTION
grantsamborn
Solution Sage
Solution Sage

In PowerQuery:
1. Highlight Activity and Product columns, and select “Merge Columns” using "_" as separator.
2. Highlight “Merged” column and select “Pivot Column” using Volume as “Values Column”.

 

 

let
  Source = Excel.Workbook(
    File.Contents("C:\Power_BI\PBI Community\expand out columns Matrix\RawData.xlsx"),
    null,
    true
  ),
  Sheet1_Sheet = Source{[Item = "Sheet1", Kind = "Sheet"]}[Data],
  #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars = true]),
  #"Changed Type" = Table.TransformColumnTypes(
    #"Promoted Headers",
    {
      {"Date", type date},
      {"Facility ID", type text},
      {"Activity", type text},
      {"Product", type text},
      {"Volume", Int64.Type}
    }
  ),
  #"Merged Columns" = Table.CombineColumns(
    #"Changed Type",
    {"Activity", "Product"},
    Combiner.CombineTextByDelimiter("_", QuoteStyle.None),
    "Merged"
  ),
  #"Pivoted Column" = Table.Pivot(
    #"Merged Columns",
    List.Distinct(#"Merged Columns"[Merged]),
    "Merged",
    "Volume",
    List.Sum
  )
in
  #"Pivoted Column"

 

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@Anonymous You can create a DAX calculated column like: Column = [Activity] & "_" & [Product]


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
grantsamborn
Solution Sage
Solution Sage

In PowerQuery:
1. Highlight Activity and Product columns, and select “Merge Columns” using "_" as separator.
2. Highlight “Merged” column and select “Pivot Column” using Volume as “Values Column”.

 

 

let
  Source = Excel.Workbook(
    File.Contents("C:\Power_BI\PBI Community\expand out columns Matrix\RawData.xlsx"),
    null,
    true
  ),
  Sheet1_Sheet = Source{[Item = "Sheet1", Kind = "Sheet"]}[Data],
  #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars = true]),
  #"Changed Type" = Table.TransformColumnTypes(
    #"Promoted Headers",
    {
      {"Date", type date},
      {"Facility ID", type text},
      {"Activity", type text},
      {"Product", type text},
      {"Volume", Int64.Type}
    }
  ),
  #"Merged Columns" = Table.CombineColumns(
    #"Changed Type",
    {"Activity", "Product"},
    Combiner.CombineTextByDelimiter("_", QuoteStyle.None),
    "Merged"
  ),
  #"Pivoted Column" = Table.Pivot(
    #"Merged Columns",
    List.Distinct(#"Merged Columns"[Merged]),
    "Merged",
    "Volume",
    List.Sum
  )
in
  #"Pivoted Column"

 

PaulDBrown
Community Champion
Community Champion

Can you please post the sample data as actual data? (As opposed to an image)





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.