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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
v-yifanw-msft
Community Support
Community Support

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!

v-yifanw-msft
Community Support
Community Support

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors