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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mmpbi
Regular Visitor

Duplicate column in the rowset error when appending files

I wrote the folowing power-query script. It calls fnGetContents, which is a custom func that removes the first 8 lines of every file (since they contain all sorts of crap I don't need). Then it expands all files into 1 big table, but not before it fetches all column names from each of tables and adds them 1 list. This is because the column names are not the same in every files and was insipired on this solution bij @ImkeF : https://community.powerbi.com/t5/Desktop/Expanding-Multiple-Data-Tables-with-Unknown-Column-Names/td...

 

 

 

 

let
    Source = Folder.Files("C:\Users\****\***\***\***"),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each fnGetContents([Folder Path]&[Name])),
   #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", List.Union(List.Transform(#"Added Custom"[Custom], each Table.ColumnNames(_)))),
in
    #"Expanded Custom"

 

 

 

 

 

However, when running it on all (40+) of my source files. I get this error-message:

mmpbi_0-1613409669265.png

 

As a solution I tried to add a List.Distinct() around the list of column names, but that doesn't solve anything.

 

Any ideas for solutions? Thanks in advance!

 

Edit: On request, here is the custom func:

 

(filepath)=>
let
    Source = Csv.Document(File.Contents((filepath)),[Delimiter=";", Columns=76, Encoding=65001, QuoteStyle=QuoteStyle.None]),
   #"Removed Top Rows" = Table.Skip(Source ,8),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true])
in
    #"Promoted Headers"

 

9 REPLIES 9
Jimmy801
Community Champion
Community Champion

Hello @mmpbi 

 

I cannot see any problems with your expand-function. Most proboably this error is caused by your custom-function. Can you share this function here?

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

I added the custom func to the original post!

Jimmy801
Community Champion
Community Champion

Hello @mmpbi 

 

can you try this function please

 

= (filepath)=>
let
    Source = Csv.Document(File.Contents((filepath)),[Delimiter=";", Encoding=65001, QuoteStyle=QuoteStyle.None]),
   #"Removed Top Rows" = Table.Skip(Source ,8),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true])
in
    #"Promoted Headers"

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Thanks. Tried it. Unfortunately it only changed the error message:

 

mmpbi_0-1613468780690.png

 

Jimmy801
Community Champion
Community Champion

Hello @mmpbi 

 

then I really don't know. I've checked your code and it's working like a charm. What you can still try though is to cancel your permissions. Go to data source settings and cancel all auhorizations.

Hope that helps

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

 

lbendlin
Super User
Super User
Vera_33
Resident Rockstar
Resident Rockstar

Hi @mmpbi 

 

In you custom function, the custom column has all tables, right? Have you checked all headers in each table? Besides, in the list, try Trim and/or Text.Lower (Upper/Proper) before List.Distinct

Thanks for your reply! The point is that the headers in most tables are the same, but there are some tables that are gonna have different headers. I want the script to append to the existing whenever a column was already found in one of the previous tables, or create a new column when it didn't yet.

Vera_33
Resident Rockstar
Resident Rockstar

Hi @mmpbi 

 

I understand your code, I have done similar one to load multiple files with different headers, but have not seen this error...can you try this, if you don't like Lowercase, Proper or Upper:

 

 

(filepath)=>
let
    Source = Csv.Document(File.Contents((filepath)),[Delimiter=";",  Encoding=65001, QuoteStyle=QuoteStyle.None]),
   #"Removed Top Rows" = Table.Skip(Source ,8),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
   custom = Table.TransformColumnNames( Table.TransformColumnNames( #"Promoted Headers", Text.Trim), Text.Lower)
in
    Custom

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.