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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
callmerain
Frequent Visitor

Power Query Editor - Moving data from one row to another only in certain columns

Hi,

I'm trying to figure out if there is any way to move data from 1 row to another (maybe based on an IF statement?) in Power Query Editor.

 

I have data that I am pulling in from excel file that is generated out of a system.  I am hoping to avoid having to change the excel file before import, if possible.

When I pull the raw data into Power Query Editor, there are leading rows with non or null data values.  I want to remove the leading rows and then promote the row with the Header data in it to the Headers.

The problem is that within these excel files, there is one set of Header data that is on a different row than all of the rest....

Here's an example:

 ABCDEFGHIJKLMN
1nullnullnullnullnullnullnullnullnullnullnullnullnullnull
2nullnullnullnullnullnullnullnullnullnullnullnullnullnull
3nullnullnullnullnullnull1/1/20232/1/20233/1/20234/1/20235/1/2023   
4nullnullnullnullnullnullnullnullnullnullnullTotalMaxRent or
5NameNumberClassCodemakemodel12345Mos.Per MthPurchase
6Sample1132310FORDF150 SCXL0150015001500031RENT
7Sample2238364FORDF150 SCXL0150015000032PURCHASE

 

There are multiple excels that I need to be able to copy/paste the Applied Steps to.  In each excel, the starting point of where the dates that I need to move will be the same, but the amount of columns that have dates will change (could be a 5 month duration, could be a 22 month duration, etc).

Any ideas on this?

 

Bonus points if you also happen to know an easy way to combine the row data that starts after that, as it seems the Header names there are getting split between two rows.

1 ACCEPTED SOLUTION
callmerain
Frequent Visitor

Solved it!

 

Going to leave my solution here for posterity:

 

First, I duplicated my import, to have something to mold.

I used Keep Rows > Keep a range of rows to pull out only the 3 rows that I wanted to deal with (in my Sample case, it would be 3, 4, and 5)

Then I transposed them, so that I was working with 3 columns.

I added a custom column with an IF statement to check the first column for / (which only my date columns would have) and to either pull the dates or the main header info from the other column:

each if [Column1] = null then [Column3] else if Text.Contains([Column1], "/") then [Column1] else [Column3])

That gave me the solution to my main problem.  To handle that secondary word split, I created another Custom Column where if the split row cell was null, it would pull from my newly created column, otherwise it would concatonate the to row cells:

each if [Column2] = null then [Headers] else Text.From([Column2]) & " " & Text.From([Column3])

Then I removed all other columns, and transposed the Column back to a Row, and Appended my original data set onto the new row.  Promoted the top row to Headers and removed all of the unneeded rows between that and the beginning of the data

 

View solution in original post

1 REPLY 1
callmerain
Frequent Visitor

Solved it!

 

Going to leave my solution here for posterity:

 

First, I duplicated my import, to have something to mold.

I used Keep Rows > Keep a range of rows to pull out only the 3 rows that I wanted to deal with (in my Sample case, it would be 3, 4, and 5)

Then I transposed them, so that I was working with 3 columns.

I added a custom column with an IF statement to check the first column for / (which only my date columns would have) and to either pull the dates or the main header info from the other column:

each if [Column1] = null then [Column3] else if Text.Contains([Column1], "/") then [Column1] else [Column3])

That gave me the solution to my main problem.  To handle that secondary word split, I created another Custom Column where if the split row cell was null, it would pull from my newly created column, otherwise it would concatonate the to row cells:

each if [Column2] = null then [Headers] else Text.From([Column2]) & " " & Text.From([Column3])

Then I removed all other columns, and transposed the Column back to a Row, and Appended my original data set onto the new row.  Promoted the top row to Headers and removed all of the unneeded rows between that and the beginning of the data

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.