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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
roscas
Helper I
Helper I

Convert Rows in Columns

I need to convert rows to Columns. If you see the picture on the left, I have the data on the right of the result, could someone please help me with this?

PQ 1.png

1 ACCEPTED SOLUTION
AlB
Super User
Super User

@roscas 

or if you prefer to do this in PQ, you can pivot the Salary type column:

AlB_1-1673423439435.png

and choose Amount as the values column:

AlB_2-1673423540941.png

See it all at work in the attached file. (OutputT is the version in PQ)

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

6 REPLIES 6
AlB
Super User
Super User

@roscas 

or if you prefer to do this in PQ, you can pivot the Salary type column:

AlB_1-1673423439435.png

and choose Amount as the values column:

AlB_2-1673423540941.png

See it all at work in the attached file. (OutputT is the version in PQ)

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

AlB
Super User
Super User

@roscas 

I misunderstood. Thought your input was your output.  In that case, you can:

1. Place ID, Name and Status in a table visual

2. Create these two measures and place them in the table visual:  

Actual = 
CALCULATE ( SUM ( InputT[Amount] ), InputT[Salary type] = "Actual" )
Benefit = 
CALCULATE ( SUM ( InputT[Amount] ), InputT[Salary type] = "Benefit" )

The result will look like:

AlB_0-1673423187160.png

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Hi thanks for your help, the solutions (formulas) are created on DAX? 

Is there a solution to do on M (Power Query)? Thanks

@roscas 


@roscas wrote:

Is there a solution to do on M (Power Query)? Thanks


looks like you have not seen my other message,  have you?

 


SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

AlB
Super User
Super User

Hi @roscas 

Just select the two columns (Actual and Benefit) and unpivot them. Then change column names as required

Place the following M code in a blank query to see the steps.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJLzE0F0Y7JJZllqUCGkYEBkDQGkrE60UpGUCVGyErMjUFKzIwhSoyhSoyRlZgagZQAFcQCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t, Status = _t, Actual = _t, Benefit = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name", type text}, {"Status", type text}, {"Actual", Int64.Type}, {"Benefit", Int64.Type}}),

    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"ID", "Name", "Status"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Salary type"}, {"Value", "Amount"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"ID", "Name", "Status", "Amount", "Salary type"})
in
    #"Reordered Columns"

 

 

AlB_1-1673380830915.png

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Hi thanks for your prompt response, but I didn't get it, I have 

 

from this data

PQ3.png

 I need a Final Table like:

PQ2.png

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors