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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sbw666
Regular Visitor

Dax help- Take value from multiple columns and create single column with multiple rows

Afternoon all, 

I'm looking for a little help on a novel situation I haven't dealt with before.

 

The scenario:

I have a dataset of invoice data for multiple companies. Depending on the company, the invoice needs to have different summary categories. I have a table relating company to invoice type, and another table with Invoice type to what categories it needs to include.

 

The problem: I can't get the categories to display as rows in a table visual ( Once I have that figured out, totaling by category should be easy)

 

I assume this would probably be a calculated table...but I was struggling with my current dax knowledge

 

Thanks for your help in advance!!

 

 

 

Data model relationships

sbw666_0-1706647023983.png

 

sbw666_1-1706647138804.png

 

Example Data:

Company

Invoice Type

A

1

B

2

C

1

D

6

E

2

F

1

 

 

Invoice Type

Row 1

Row 2

Row 3

1

Category 1

Category 2

Category 3

2

Category 2

Category 4

 

6

Category 5

 

 

 

Invoice ID

Company

Amount

10000

A

53045

100002

B

40154

190004

A

45379

280006

D

71394

370008

E

54946

460010

F

13384

550012

F

81174

640014

B

11641

730016

C

84162

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sbw666 ,

Based on the information you have provided, you can follow the steps below:

1.Unpivoted Row1, Row2 and Row3 in Power Query.

vyifanwmsft_1-1706679033825.png

vyifanwmsft_0-1706678909402.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJOLElNzy+qVEDhGCFzjJVidaKVjHDKmwA5YCVmyKKmIFGQRCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Invoice Type" = _t, Row1 = _t, Row2 = _t, Row3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Invoice Type", Int64.Type}, {"Row1", type text}, {"Row2", type text}, {"Row3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Invoice Type"}, "Attribute", "Value"),
    #"Removed Bottom Rows" = Table.RemoveLastN(#"Unpivoted Columns",2),
    #"Removed Alternate Rows" = Table.AlternateRows(#"Removed Bottom Rows",5,1,6),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Alternate Rows",{{"Value", "Category"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Attribute"})
in
    #"Removed Columns"

 2.Use measure to calculate Total Amount by Invoice Type.

Total Amount = 
CALCULATE (
    SUM ( Table3[Amount] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Invoice Type] = SELECTEDVALUE ( 'Table'[Invoice Type] )
    )
)

 Final output:

vyifanwmsft_2-1706679330858.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
sbw666
Regular Visitor

Thank you Greg and v-yifanw!! I was way over thinking it apparently, I had actually started with it in the tranposed format and switched it to have one row per invoice type because I was thinking it would make the relationship easier.

@v-yifanw ... the SelectedValue() expression was the key to what I was missing!

 

Again...thank you both!

Anonymous
Not applicable

Hi @sbw666 ,

Based on the information you have provided, you can follow the steps below:

1.Unpivoted Row1, Row2 and Row3 in Power Query.

vyifanwmsft_1-1706679033825.png

vyifanwmsft_0-1706678909402.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJOLElNzy+qVEDhGCFzjJVidaKVjHDKmwA5YCVmyKKmIFGQRCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Invoice Type" = _t, Row1 = _t, Row2 = _t, Row3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Invoice Type", Int64.Type}, {"Row1", type text}, {"Row2", type text}, {"Row3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Invoice Type"}, "Attribute", "Value"),
    #"Removed Bottom Rows" = Table.RemoveLastN(#"Unpivoted Columns",2),
    #"Removed Alternate Rows" = Table.AlternateRows(#"Removed Bottom Rows",5,1,6),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Alternate Rows",{{"Value", "Category"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Attribute"})
in
    #"Removed Columns"

 2.Use measure to calculate Total Amount by Invoice Type.

Total Amount = 
CALCULATE (
    SUM ( Table3[Amount] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Invoice Type] = SELECTEDVALUE ( 'Table'[Invoice Type] )
    )
)

 Final output:

vyifanwmsft_2-1706679330858.png

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@sbw666 Seems to me that you should unpivot your Row1, Row2 and Row3 columns.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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