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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Anonymous
Not applicable

Aligning Column Headers with Column Data

I have 2 different Excel tables I'm connecting to in Power Query and have noticed that some of the Column Headers do not match the Column Data. I need to append these 2 tables together, but the Headers need to be identical. I'm looking for a way to shift the column headers or column data in Table 2 so that they align. I listed an example below. My actual data has close to 100 columns so simply renaming the columns & deleteing the empty one will not work.

 

Capture2.PNG

1 ACCEPTED SOLUTION
Nolock
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

I have a solution for you. It searches for all columns which are empty and removes them. Then shift the names of columns.

I've developed it as a function which will be easier to integrate in your solution.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoCYiBKBuIUIE5VitWJVjIEsowgEsZAbALEpkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Customer = _t, Product = _t, Qty = _t, Cost = _t, Sell = _t, #" " = _t]),
    
    fnShiftByOneEmptyColumn = (tbl as table) as table =>
        let
            // get column names of the origin table
            ColumnNames = Table.ColumnNames(tbl),
            // find columns which don't contain any values
            EmptyColumns = List.Select(
                ColumnNames, 
                each List.MatchesAll(Table.Column(tbl, _), each _ = null or _ = "")
            ),
            // remove empty column from the origin table
            RemoveEmptyColumn = Table.RemoveColumns(tbl, EmptyColumns),
            // rename columns
            RenameColumns = Table.RenameColumns(
                RemoveEmptyColumn, 
                List.Zip(
                    {
                        // columns of the origin table without empty columns
                        Table.ColumnNames(RemoveEmptyColumn), 
                        // N-x columns of the origin table
                        List.RemoveLastN(ColumnNames, List.Count(EmptyColumns))
                    }
                )
            )
        in
            RenameColumns,

    Result = fnShiftByOneEmptyColumn(Source)
in
    Result

View solution in original post

1 REPLY 1
Nolock
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

I have a solution for you. It searches for all columns which are empty and removes them. Then shift the names of columns.

I've developed it as a function which will be easier to integrate in your solution.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoCYiBKBuIUIE5VitWJVjIEsowgEsZAbALEpkqxsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Customer = _t, Product = _t, Qty = _t, Cost = _t, Sell = _t, #" " = _t]),
    
    fnShiftByOneEmptyColumn = (tbl as table) as table =>
        let
            // get column names of the origin table
            ColumnNames = Table.ColumnNames(tbl),
            // find columns which don't contain any values
            EmptyColumns = List.Select(
                ColumnNames, 
                each List.MatchesAll(Table.Column(tbl, _), each _ = null or _ = "")
            ),
            // remove empty column from the origin table
            RemoveEmptyColumn = Table.RemoveColumns(tbl, EmptyColumns),
            // rename columns
            RenameColumns = Table.RenameColumns(
                RemoveEmptyColumn, 
                List.Zip(
                    {
                        // columns of the origin table without empty columns
                        Table.ColumnNames(RemoveEmptyColumn), 
                        // N-x columns of the origin table
                        List.RemoveLastN(ColumnNames, List.Count(EmptyColumns))
                    }
                )
            )
        in
            RenameColumns,

    Result = fnShiftByOneEmptyColumn(Source)
in
    Result

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.