Forum Discussion
Shift Values to the Left for certain rows
- Anonymous3 years ago
Hi Einomi ,
Suppose we have:
You may consider creating three new conditional columns. like this:
= if [Data.Column6] = null then [Data.Column7] else [Data.Column6]= if [Data.Column6] = null then [Data.Column8] else [Data.Column7]= if [Data.Column6] = null then null else [Data.Column8]Then remove and rename the columns.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmOlWJ1oJQQnFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data.Column6 = _t, Data.Column7 = _t, Data.Column8 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data.Column6", Int64.Type}, {"Data.Column7", Int64.Type}, {"Data.Column8", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Data.Column6] = null then [Data.Column7] else [Data.Column6]), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Data.Column6] = null then [Data.Column8] else [Data.Column7]), #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if [Data.Column6] = null then null else [Data.Column8]), #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Data.Column6", "Data.Column7", "Data.Column8"}), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Data.Column6"}, {"Custom.1", "Data.Column7"}, {"Custom.2", "Data.Column8"}}) in #"Renamed Columns"Best Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hi Einomi ,
Suppose we have:
You may consider creating three new conditional columns. like this:
= if [Data.Column6] = null then [Data.Column7] else [Data.Column6]= if [Data.Column6] = null then [Data.Column8] else [Data.Column7]= if [Data.Column6] = null then null else [Data.Column8]
Then remove and rename the columns.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmOlWJ1oJQQnFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data.Column6 = _t, Data.Column7 = _t, Data.Column8 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Data.Column6", Int64.Type}, {"Data.Column7", Int64.Type}, {"Data.Column8", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Data.Column6] = null
then [Data.Column7] else [Data.Column6]),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Data.Column6] = null
then [Data.Column8] else [Data.Column7]),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each if [Data.Column6] = null
then null else [Data.Column8]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Data.Column6", "Data.Column7", "Data.Column8"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Data.Column6"}, {"Custom.1", "Data.Column7"}, {"Custom.2", "Data.Column8"}})
in
#"Renamed Columns"
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Thanks Gao 🙂
Anonymousit works good. I had to shift 6 or 7 columns but the logic works 🙂