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 data from folders with same name

I have a folder tree where I want to import multiple .csv file with the same name. I would like to use the folder path (through some column column splitting to create a new source name for each file.  

 

If I do no column manipulations and simply Combine the files, I will get a Column name (Source) which uses the filename (and for my case this is not useful since they all have the same file).

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

 

As soon I a begin doing any column manipulation, I no longer get "Souce" out.  In the example below, I've done all of the manipulation I want but want to include "TestName" into my data set. But when I "Combine Files" I'm not sure how to include this new Column into the 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 (10)", each #"Transform File from BITest3 (10)"([Content])),
    #"Removed Other Columns1" = Table.SelectColumns(#"Invoke Custom Function2", {"Transform File from BITest3 (10)"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File from BITest3 (10)", Table.ColumnNames(#"Transform File from BITest3 (10)"(#"Sample File (10)"))),
    #"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!

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