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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
EC305
New Member

Handling Missing Columns in Combined Files to Maintain Header Alignment

When combining six files for example, sometimes one or a few of the files will have one column (titled "YYY") with no data which causes the column to not report in that file and headers to shift. Example, files 1-3 and 5 have these three columns with data: "XXX", "YYY" and "ZZZ". Then files 4 and 6 are missing column "YYY", so column "ZZZ" is shifted next to column "XXX".

Example   
Col. A (file name)Col. LCol. MCol. N
…1.txtXXXYYYZZZ
…2.txtXXXYYYZZZ
…3.txtXXXYYYZZZ
…4.txtXXXZZZ 
…5.txtXXXYYYZZZ
…6.txtXXXZZZ 

Is there a way to look at the first row in column A ending in "...1.txt", and check if column M has "YYY" as the header, if yes do nothing and if no then shift every column from column M - W over one column to the right for all rows containing "...1.txt" in column A. This would be repeated for all other file names through "...6.txt". 

Thanks for any help in advanced!

1 ACCEPTED SOLUTION
rohit1991
Super User
Super User

In Power BI, you can use Power Query to handle this issue:

  1. Load Data: Load your combined file into Power Query.
  2. Identify Misalignment:
    • Add a conditional column: = if Text.EndsWith([Col. A], "1.txt") and [Col. M] <> "YYY" then true else false.
  3. Shift Columns:
    • Duplicate your table.
    • Shift columns M-W for misaligned rows using a custom column and transformation logic.
  4. Combine Data:
    • Append the corrected table back to the original, ensuring all rows align.

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

7 REPLIES 7
v-veshwara-msft
Community Support
Community Support

Hi @EC305 ,
May i ask if you have resolved your query. If yes, please mark the helpful reply as 'Accespt as Solution' to assist others with similar queries. If you still need assistance please reach out.

Thank you.

v-veshwara-msft
Community Support
Community Support

Hi @EC305 ,

We just wanted to check in again regarding your issue. If you've found a solution, marking the reply as the solution and leaving a kudos would be greatly appreciated, it helps the community and others with similar questions.

If you're still facing challenges or have further questions, please reach out.

Thank you.

v-veshwara-msft
Community Support
Community Support

Hi @EC305 ,
Just wanted to check if the query has been resolved at your end or if any of the solutions provided met your requirements. If so, please mark the helpful reply as the solution to help others in the community with similar queries.
If further assistance is needed, please reach out.

Thank you.

Omid_Motamedise
Super User
Super User

In power Query by appending the queris, the table will append based on the column name not the order of columns, so no problem in your case also.

but if you insiste on your case, I recomend to create a blank table including all the six columns, and then use it as the first table in the appending process.

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
dufoq3
Super User
Super User

Hi @EC305, check this:

 

Output

dufoq3_0-1736707704638.png

 

let
    Data = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WetSwzFCvpKJESUcpIiICSEZGRgLJqKgopVgdsLQRfmlj/NImKNIgCR0lBZikKX69Ztj1xgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Col. A (file name)" = _t, #"Col. L" = _t, #"Col. M" = _t, #"Col. N" = _t]),
    ReplacedValue = Table.ReplaceValue(Data," ",null,Replacer.ReplaceValue,{"Col. N"}),
    Source = Table.Group(ReplacedValue, {"Col. A (file name)"}, {{"Data", each _, type table}}, 0),
    Ad_Shifted = Table.AddColumn(Source, "Shifted", each 
        [ a = [Data],
          b = List.RemoveMatchingItems(Table.ColumnNames(a), {"Col. M"}),
          c = if Table.First(a)[#"Col. M"] = "YYY" then Table.RenameColumns(Table.SelectColumns(a, b), List.Zip({ b, List.RemoveLastN(Table.ColumnNames(a)) })) else a
        ][c], type table),
    CombinedShifted = Table.Combine(Ad_Shifted[Shifted]),
    RemovedNullColumns =
        [ a = Table.PromoteHeaders(Table.DemoteHeaders(Table.Profile(CombinedShifted))),
          b = Table.SelectRows(a, each [NullCount] <> [Count])[Column],
          c = Table.SelectColumns(CombinedShifted, b)
        ][c]
in
    RemovedNullColumns

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

BA_Pete
Super User
Super User

Hi @EC305 ,

 

Can you provide examples of actual source data please, one where the column is present, and one where it is not? Please also provide an example of what your desired outcome is based on these two new examples provided.

I think I understand the issue, but the question is a bit too vague to be sure.

 

For more info on how to provide good data for us to work with, please read through this:

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/4294... 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




rohit1991
Super User
Super User

In Power BI, you can use Power Query to handle this issue:

  1. Load Data: Load your combined file into Power Query.
  2. Identify Misalignment:
    • Add a conditional column: = if Text.EndsWith([Col. A], "1.txt") and [Col. M] <> "YYY" then true else false.
  3. Shift Columns:
    • Duplicate your table.
    • Shift columns M-W for misaligned rows using a custom column and transformation logic.
  4. Combine Data:
    • Append the corrected table back to the original, ensuring all rows align.

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors