Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi All,
I am trying to shift a text from one column to a neighbouring one.
While importing data from CSV I have ended up with row containing my "names" that are shifted versus where I needed them to be.
I there an easy way to move "text" (CH1:Open Circuit) from column 1 to column 2 (blank)
for all columns?
1 ! 2 ! 3 ! 4 ! 5 ! 6 !
name ! ! name ! ! name ! !
to
1 ! 2 ! 3 ! 4 ! 5 ! 6 !
! name ! ! name ! ! name !
I have tried some sort of merging by extracting only relevant names, removing blanks and transposing thus creating a table with names... unfortunately merging creates a mess with the data not aligning at all.
Solved! Go to Solution.
Hi @grzego12 ,
instead of shifting the data, I would "shift" the column names like so:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kvMTTVS0lECIhDTBME0AzFjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
OldColumnNames = Table.ColumnNames(Source),
NewColumnNames = List.Skip(OldColumnNames) & {"LastColumn"},
NestedRenameList = List.Zip({OldColumnNames, NewColumnNames}),
#"Renamed Columns" = Table.RenameColumns(Source, NestedRenameList)
in
#"Renamed Columns"
See also attached file.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
How many columns are there which are misaligned?
My first advice would be to check the Source settings on your CSV file and ensure there isn't something you can fix in there to get the columns to align properly.
If that doesn't work, you might be able to get your desired result using a transpose and Fill Down. Then transpose again.
Another Option:
You could either use the Row Index for this, or use a conditional column and basically say If column2 is blank, then column1 else column 2. There is probably a way to write a custom function that will repeat this for every column pair you need, but I'm not sure. @ImkeF do you have any ideas?
This would be how to add the correct Column 2 values:
= Table.AddColumn(#"Removed BlankRows1", "Column2 Fixed", each if [Column2] = null then [Column1] else [Column2])
You would need to then delete the original column 2 and repeat for every iteration, so not very efficient.
Did you also want to remove the text from Column1 as well once it is copied into Column2?
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Hi @grzego12 ,
instead of shifting the data, I would "shift" the column names like so:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kvMTTVS0lECIhDTBME0AzFjYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
OldColumnNames = Table.ColumnNames(Source),
NewColumnNames = List.Skip(OldColumnNames) & {"LastColumn"},
NestedRenameList = List.Zip({OldColumnNames, NewColumnNames}),
#"Renamed Columns" = Table.RenameColumns(Source, NestedRenameList)
in
#"Renamed Columns"
See also attached file.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi All,
Thank you for your help. Much appreciated. Finally I can get cracking with my data !
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Hi @AllisonKennedy ,
yes, it should work like that.
Sure, you can shift into the other direction instead. But I thought my original solution looked good, TBH 🙂
Anyhow, it would work like so:
NewColumnNames = {"FirstColumn"} & List.RemoveLastN(OldColumnNames,1),
See file attached.
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Hi @grzego12
Right click on the name of the last loclumn and select Move --> To Begining
You can do it on all other columns as Left, Right or To End
Hope it resolves your issue? Did I answer your question? Mark my post as a solution! Appreciate your Kudos, Press the thumbs up button!! Linkedin Profile |
Hi Pranit828,
Much appreciate your response but I did not want to move whole column.
I would like to shift a single row or "cell with text" to the "right" into the neighbouring "cell".
Eventually automatically copy "name" from a cell into a neighbouring cell within a single row.
in excell you could just do it with "=" sign but here its just get complicated.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
93 | |
77 | |
65 | |
53 |
User | Count |
---|---|
147 | |
106 | |
104 | |
87 | |
61 |