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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
dzaba
Frequent Visitor

Move columns in power query

Hi,

 

I stucked with one step in power query

 

I need to make a list of Users. My table look right now like this

 

USER_IDwork typeValuework type2Value2
woRdaOther1 0
fErmoOther1 0
tuReDservice1 0
RevaNparts1 0
EellhOther0,5parts0,5
OpijsOther0,5parts0,5
JerysOther1 0
hiieAOther1 0
HTWaaparts1 0
XZU3cc10Other0,5Other0,5
DGG55533Other1 0
XZU3230Other1 0
XeeeecOther1 0
vvvRRRGparts1 0
SDF343parts1 0
XZU0851Other1 0
MERcheasOther0,5sales0,5
Ttyywysales1 0
OPDOSsales1 0
Jdksiusales1 0
Loeurksales1  

 

to make next analysis I need to have the table

 

User | work | value. So I need to transfer 

work type2Value2

 under the column

work typeValue

 

Any idea? 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

See this code. It turns this:

edhans_0-1618252865004.png

Into this:

edhans_1-1618252950344.png

You weren't clear on what you wanted, so if Work Type 2 had a value and Work Type 1 said Other, I used Work Type 2.


With the values, I just added them together.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZBBa4QwEIX/iuTsITYN9FrQtUi3luiyZcVDiFPMrsUl0Yj/vvGWYqcNDOHxPV5epmnIMopOkpiUUw/G34mfyA8lbdyQz8x8jSidZgGpVxaM0wp2XICTb17dpZnsjmYwDH2QTWMeeDe1ucq7vtp/XQWY1aI9e63hGaUv9VlKtOXH5cSUSuiuQqg2Y5rnnHPG0He2pAdGcQ7+KBQ754QQOVq0Sg/skf31D/rEEzT+mAnVg9yv2soBwlXX07ouawB+5pTvaVmhtOhuVs8ofh1hNrdfcETa9hs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [USER_ID = _t, #"work type" = _t, Value = _t, #"work type2" = _t, Value2 = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,",",".",Replacer.ReplaceText,{"Value", "Value2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Value", Currency.Type}, {"Value2", Currency.Type}}),
    #"Replaced Value1" = Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Value", "Value2"}),
    #"Added New Work Type" = Table.AddColumn(#"Replaced Value1", "New Work Type", each if [work type] = "Other" and [work type2] <> " " then [work type2] else [work type]),
    #"Inserted Addition" = Table.AddColumn(#"Added New Work Type", "New Value", each [Value] + [Value2], Currency.Type),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Addition",{{"New Work Type", type text}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type1",{"USER_ID", "New Work Type", "New Value"})
in
    #"Removed Other Columns"

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 

If that isn't what you want, provide sample output with an explanation of how you got there.

How to get good help fast. Help us help you.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

See this code. It turns this:

edhans_0-1618252865004.png

Into this:

edhans_1-1618252950344.png

You weren't clear on what you wanted, so if Work Type 2 had a value and Work Type 1 said Other, I used Work Type 2.


With the values, I just added them together.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZBBa4QwEIX/iuTsITYN9FrQtUi3luiyZcVDiFPMrsUl0Yj/vvGWYqcNDOHxPV5epmnIMopOkpiUUw/G34mfyA8lbdyQz8x8jSidZgGpVxaM0wp2XICTb17dpZnsjmYwDH2QTWMeeDe1ucq7vtp/XQWY1aI9e63hGaUv9VlKtOXH5cSUSuiuQqg2Y5rnnHPG0He2pAdGcQ7+KBQ754QQOVq0Sg/skf31D/rEEzT+mAnVg9yv2soBwlXX07ouawB+5pTvaVmhtOhuVs8ofh1hNrdfcETa9hs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [USER_ID = _t, #"work type" = _t, Value = _t, #"work type2" = _t, Value2 = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,",",".",Replacer.ReplaceText,{"Value", "Value2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"Value", Currency.Type}, {"Value2", Currency.Type}}),
    #"Replaced Value1" = Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Value", "Value2"}),
    #"Added New Work Type" = Table.AddColumn(#"Replaced Value1", "New Work Type", each if [work type] = "Other" and [work type2] <> " " then [work type2] else [work type]),
    #"Inserted Addition" = Table.AddColumn(#"Added New Work Type", "New Value", each [Value] + [Value2], Currency.Type),
    #"Changed Type1" = Table.TransformColumnTypes(#"Inserted Addition",{{"New Work Type", type text}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type1",{"USER_ID", "New Work Type", "New Value"})
in
    #"Removed Other Columns"

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.

 

If that isn't what you want, provide sample output with an explanation of how you got there.

How to get good help fast. Help us help you.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors