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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Hsilva
Helper I
Helper I

Merging Columns

Hi Community;

I have an excel report (which comes from MYOB) where some columns have header and others do not. Sometimes the data splits in two columns, so I have to merge these two columns in order to get the 100% of the detail. The problem is that the position of the columns change from one report to another, for example:

 

Report A (total quantity = 15 in two columns)

ItemColumn2Column3 Quantity
Anull10 
Bnull 5

 

Report B (total quantity =15 in one column)

ItemColumn2Quantity
Anull10
Bnull5
   

 

I my first query I did Promote headers, then merge Columns "Quantity" with "Column3" to get the total = 15.

In the second report, I do not need to merge, but when merging I got the error "Column3 wasn't found"

 

Any suggestions would be much appreciated.

Regards

Humberto

3 REPLIES 3
Anonymous
Not applicable

Hi @Hsilva ,

 

Based on this:

In the second report, I do not need to merge, but when merging I got the error "Column3 wasn't found"

 

You may have referenced a no-existing column . So please navigate to the wrong Applied step.

Eyelyn9_0-1648109102967.png

And If possible, please share the whole M syntax to help us clarify your scenario.

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hsilva
Helper I
Helper I

Hi Vijay, thank you very much for your prompt answer.

Apologies I think I made a mistake simplifying the example. The code works if the file has one empty column, however it has many and Ialso applyed few steps to get the header.

If you can have a look to the attached file and give me some advice would be great.

Thank you again for your help.

Humberto

 

https://primaryhealth-my.sharepoint.com/:x:/g/personal/josef_silva_primaryhealthcare_com_au/ERsa24vI... 

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use following m code for dynamic merging of columns (Solution demonstrating this is uploaded to https://1drv.ms/x/s!Akd5y6ruJhvhuS9iB3OYRgx-5Bjb?e=0CkeKS )

let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    ListOfColumns = List.RemoveFirstN(Table.ColumnNames(Source),1),
    TransformListOfColumns = List.Transform(ListOfColumns, each {_, type text}),
    #"Transform Column Types" = Table.TransformColumnTypes(Source, TransformListOfColumns),
    #"Combine Columns" = Table.CombineColumns(#"Transform Column Types",ListOfColumns,Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Final Quantity"),
    #"Result" = Table.TransformColumnTypes(#"Combine Columns", {"Final Quantity", type number})
in
    Result

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.