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

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

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
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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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 Solution Authors
Top Kudoed Authors