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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
WiesHerd
New Member

PowerQuery: Repeat Header in Column until Next Header

I think this is possible but I have no idea how to accomplish this.  What I am trying to do is repeat a row.  If you look under, the second screenshot below line description column, you will see headers like Salaires & Wages.  They are always identified as LineSubSequence 0 and maybe this is the key.  Is there a way to make the Salaries and Wages go on every single line blow the subaccounts.

 

So it would look like this:

 

   
Before:  
   
Salaries & Wages  
6005000000Productive Wages 
6005050000Productive Premium 
6025000000CTO Wages 
6025050000CTO_COB Payout 
6040000000Non-Productive Wages 
   
   
After.  
Salaries & Wages6005000000Productive Wages
Salaries & Wages6005050000Productive Premium
Salaries & Wages6025000000CTO Wages
Salaries & Wages6025050000CTO_COB Payout
Salaries & Wages6040000000Non-Productive Wages

 

WiesHerd_0-1647981875644.png

 

 

4 REPLIES 4
wdx223_Daniel
Super User
Super User

assume the Line_Description column is the third column, then try this

NewStep=#table(Table.ColumnNames(PreviousStepName),List.Accumulate(Table.ToRows(PreviousStepName),{{},""},(x,y)=>if List.Contains({"0".."9"},Text.Start(y{2},1)) then {x{0}&{List.ReplaceRange(y,2,1,{x{1}&y{2}})},x{1}} else {x{0}&{y},y{2}}){0})

Just a forewarning I am super new so you will have to treat me like a tempermental 2  year old.  This is a bit more complicated in terms of functions than I am used to.  I am learning but just need a little bit of time please 

WiesHerd_0-1648066711952.png

 

  If you can walk me through slowly I would be forever greatful please.

 

MahoneyPat.Yes Dynamically would be great.  This is just a GL PL statement dump.  It gets refreshed daily but the dataset comes out looking this way and I have no way to format it so the corresponding header is in row format.  So if it can do it dynamically where it can find the header row Purchase Services, Utilities, Salaries and Wages etc. and put it next to the corresponding sub account would be awesome.  

 

wdx223_Daniel ..You just blew my mind with all do respect.  Can you walk me on how to apply this formula this is what I got so far but I get an error message.

1.

WiesHerd_1-1648066712097.png

 

2.

 

WiesHerd_2-1648066712050.png

 

 

Also the source is a SQL server database PMR_Reporting_ Work.

WiesHerd_3-1648066712045.png

 

 

Sorry for the silly questions 

WiesHerd_4-1648066711954.png

 

mahoneypat
Microsoft Employee
Microsoft Employee

Do you need to dynamically use the column name(s)? Or is it just the one prefix you need to add? if the latter, you can just convert that column to type text, and on the Transform tab, choose Format/Add Prefix, and enter Salaries & Wages to the pop-up box. If the former, you can dynamically grab the column name(s) from the Table.ColumnNames function applied to the previous step.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Just a forewarning I am super new so you will have to treat me like a tempermental 2  year old.  This is a bit more complicated in terms of functions than I am used to.  I am learning but just need a little bit of time please 🙂  If you can walk me through slowly I would be forever greatful please.

 

MahoneyPat.Yes Dynamically would be great.  This is just a GL PL statement dump.  It gets refreshed daily but the dataset comes out looking this way and I have no way to format it so the corresponding header is in row format.  So if it can do it dynamically where it can find the header row Purchase Services, Utilities, Salaries and Wages etc. and put it next to the corresponding sub account would be awesome.  

 

wdx223_Daniel ..You just blew my mind with all do respect.  Can you walk me on how to apply this formula this is what I got so far but I get an error message.

1.

WiesHerd_1-1648033528234.png

2.

 

WiesHerd_2-1648033549411.png

 

Also the source is a SQL server database PMR_Reporting_ Work.

WiesHerd_3-1648037472075.png

 

Sorry for the silly questions 😞

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.