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
tchiles
Frequent Visitor

Importing Files from Folder with same filename

I'm using Query Editor to load multiple CSV file from a folder tree with the same filename. I want to change to source name of each file with a new name I can extract from the file path.  

 

If I combine the files with out any column changes, I will get a Source field with the same filename.

 

let
    Source = Folder.Files("C:\Users\ttt\Desktop\BITest3"),
    #"Invoke Custom Function1" = Table.AddColumn(Source, "Transform File from BITest3 (8)", each #"Transform File from BITest3 (8)"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File from BITest3 (8)"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from BITest3 (8)", Table.ColumnNames(#"Transform File from BITest3 (8)"(#"Sample File (8)"))),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"Source.Name", type text}, {"X", Int64.Type}, {"Y", Int64.Type}, {"Z", type number}})
in
    #"Changed Type"

 

 

If I make any changes to these columns, the "Source" Column is removed when I do the combine.  I was trying to do several column changes and end up with "Content" and "TestName" folders:

let
    Source = Folder.Files("C:\Users\ttt\Desktop\BITest3"),
    #"Invoke Custom Function1" = Table.AddColumn(Source, "Transform File from BITest3 (8)", each #"Transform File from BITest3 (8)"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns1",{"Source.Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Transform File from BITest3 (8)"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Folder Path", Splitter.SplitTextByDelimiter("\", QuoteStyle.Csv), {"Folder Path.1", "Folder Path.2", "Folder Path.3", "Folder Path.4", "Folder Path.5", "Folder Path.6", "Folder Path.7"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Folder Path.1", type text}, {"Folder Path.2", type text}, {"Folder Path.3", type text}, {"Folder Path.4", type text}, {"Folder Path.5", type text}, {"Folder Path.6", type text}, {"Folder Path.7", type text}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Changed Type",{"Folder Path.1", "Folder Path.2", "Folder Path.3", "Folder Path.4", "Folder Path.5", "Folder Path.7"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Folder Path.6", "TestName"}})
in
    #"Renamed Columns"

But once I try and Combine the files, I do not konw how to include this newly created Column "TestName" as part of my data set.

 

let
    Source = Folder.Files("C:\Users\tchiles\Desktop\BITest3"),
    #"Invoke Custom Function1" = Table.AddColumn(Source, "Transform File from BITest3 (8)", each #"Transform File from BITest3 (8)"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns1",{"Source.Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Transform File from BITest3 (8)"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "Folder Path", Splitter.SplitTextByDelimiter("\", QuoteStyle.Csv), {"Folder Path.1", "Folder Path.2", "Folder Path.3", "Folder Path.4", "Folder Path.5", "Folder Path.6", "Folder Path.7"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Folder Path.1", type text}, {"Folder Path.2", type text}, {"Folder Path.3", type text}, {"Folder Path.4", type text}, {"Folder Path.5", type text}, {"Folder Path.6", type text}, {"Folder Path.7", type text}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Changed Type",{"Folder Path.1", "Folder Path.2", "Folder Path.3", "Folder Path.4", "Folder Path.5", "Folder Path.7"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Folder Path.6", "TestName"}}),
    #"Invoke Custom Function2" = Table.AddColumn(#"Renamed Columns", "Transform File from BITest3 (9)", each #"Transform File from BITest3 (9)"([Content])),
    #"Removed Other Columns1" = Table.SelectColumns(#"Invoke Custom Function2", {"Transform File from BITest3 (9)"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from BITest3 (9)", Table.ColumnNames(#"Transform File from BITest3 (9)"(#"Sample File (9)"))),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Table Column1",{{"X", Int64.Type}, {"Y", Int64.Type}, {"Z", type number}})
in
    #"Changed Type1"

Any help would be greatly appreciated. 

 

Thanks,

Todd

0 REPLIES 0

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