Forum Discussion

sbw666's avatar
sbw666
Regular Visitor
2 years ago
Solved

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

 

 

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

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi sbw666 ,

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

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

    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:

    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.

3 Replies

  • Anonymous's avatar
    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.

    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:

    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.

  • sbw666's avatar
    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!