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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Holly454
Frequent Visitor

Power Query running through each connected file each time new step added

Hello all

 

I am using Power Query in Excel 365. I connected using Files From Folder to import 10 csv files, each approx 3000 rows, 20 columns.

 

In my Transform Sample File step, only very basic transformations were made to create the custom function transformation.

To get around the fact that they have different headers, I drilled down into the column with the tables and used the following to extract a dynamic list of headers, which I then referenced when I expanded: (Thanks @wynhopkins !)

List.Union (List.Transform( PreExpand[Transform File], each Table.ColumnNames(_)) )

 

Everytime I add a step after expanding it takes around 10 minutes to apply it - below is a screenshot of the bottom right of my screen showing it cycling through each individual file. Each step is just basic from the UI like change type or replace value.

Holly454_0-1678213317021.png

 

I tried adding Table.Buffer as the first step after expanding but it made no difference. I also tried keeping just the top 100 rows but this also had no impact.

 

Any idea what might be causing this and how I can fix it please?

 

 

 

2 ACCEPTED SOLUTIONS

Hi @Holly454 

 

Sorry for the late reply.

 

I see, you've used the wizard to combine the files.

 

Can you please try the old-fashioned way below:

 

 

let
    Source = Folder.Files(REDACTED),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Content", "Name"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "CsvDocument", each Csv.Document([Content])),
    // try to standardize column names like this
    #"Added CsvDocumentStandardColumns" = Table.AddColumn(#"Added Custom", "CsvDocumentStandardColumns", each Table.RenameColumns([CsvDocument],{
        // add below all renames needed for all files
        {"Columnx", "AnotherColumnName"}, 
        {"ColumnY", "Something"}
        // ...
    // below will make sure you get no error case a rename does not apply
    }, MissingField.Ignore)) 
in
    #"Added CsvDocumentStandardColumns"

 

 

And then Expand...

ams1_1-1678790288831.png

 

...and then add all your subsequent steps.

 

IF/when you notice performance problems, please paste here your new query based on my initial code.

 

I edited my answer as I saw you have different column names... let's hope this works.

 

Please mark this as answer if it helped.

View solution in original post

Holly454
Frequent Visitor

This worked beautifully - thank you so much!

View solution in original post

7 REPLIES 7
ams1
Super User
Super User

Hi @Holly454 ,

 

At least I would need to see some code in order to try to help.

 

If you post code, don't forget to mask out confidential information!

Holly454
Frequent Visitor

Hi ams1, thanks for getting back to me. 

The code for my main query is here:

let
Source = Folder.Files(REDACTED),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
PreExpand = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
Headers = List.Union(List.Transform(PreExpand[Transform File],each Table.ColumnNames(_))),
ReadyToExpand = PreExpand,
#"Expanded Transform File" = Table.ExpandTableColumn(ReadyToExpand, "Transform File", Headers),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Transform File",{"Source.Name", "Sheet", "false"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Columns", {"Employee ID"}),
#"Removed Columns1" = Table.RemoveColumns(#"Removed Duplicates",{"Email", "Employee_Accrual_2012"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns1",{{"Employee_Accrual_2022", type number}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,0,Replacer.ReplaceValue,{"Employee_Accrual_2022"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",null,0,Replacer.ReplaceValue,{"Annual Holiday Accural", "Opening bal Jan 2012", "Closing Hol Balance Dec 2012", "Days Accrued2012", "TOIL2012", "Hols taken in2012 ", "Buy Backs2012 ", "Holiday Adjustments2012 ", "Opening bal Jan 2013", "Closing Hol Balance Dec 2013", "Days Accrued2013", "TOIL2013", "Hols taken in2013 ", "Buy Backs2013 ", "Holiday Adjustments2013 ", "Employee_Accrual_2013", "Opening bal Jan 2014", "Closing Hol Balance Dec 2014", "Days Accrued2014", "TOIL2014", "Hols taken in2014 ", "Buy Backs2014 ", "Holiday Adjustments2014 ", "Employee_Accrual_2014", "Opening bal Jan 2015", "Closing Hol Balance Dec 2015", "Days Accrued2015", "TOIL2015", "Hols taken in2015 ", "Buy Backs2015 ", "Holiday Adjustments2015 ", "Employee_Accrual_2015", "Opening bal Jan 2016", "Closing Hol Balance Dec 2016", "Days Accrued2016", "TOIL2016", "Hols taken in2016 ", "Buy Backs2016 ", "Holiday Adjustments2016 ", "Employee_Accrual_2016", "Opening bal Jan 2017", "Closing Hol Balance Dec 2017", "Days Accrued2017", "TOIL2017", "Hols taken in2017 ", "Buy Backs2017 ", "Holiday Adjustments2017 ", "Employee_Accrual_2017", "Opening bal Jan 2018", "Closing Hol Balance Dec 2018", "Days Accrued2018", "TOIL2018", "Hols taken in2018 ", "Buy Backs2018 ", "Holiday Adjustments2018 ", "Employee_Accrual_2018", "Opening bal Jan 2019"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value1",{{"Holiday Adjustments2022 ", type number}}),
#"Replaced Value2" = Table.ReplaceValue(#"Changed Type1",null,0,Replacer.ReplaceValue,{"Closing Hol Balance Dec 2019", "Days Accrued2019", "TOIL2019", "Hols taken in2019 ", "Buy Backs2019 ", "Holiday Adjustments2019 ", "Employee_Accrual_2019", "Opening bal Jan 2020", "Closing Hol Balance Dec 2020", "Days Accrued2020", "TOIL2020", "Hols taken in2020 ", "Buy Backs2020 ", "Holiday Adjustments2020 ", "Employee_Accrual_2020", "Opening bal Jan 2021", "Closing Hol Balance Dec 2021", "Days Accrued2021", "TOIL2021", "Hols taken in2021 ", "Buy Backs2021 ", "Holiday Adjustments2021 ", "Employee_Accrual_2021", "Opening bal Jan 2022", "Closing Hol Balance Dec 2022", "Days Accrued2022", "TOIL2022", "Hols taken in2022 ", "Buy Backs2022 ", "Holiday Adjustments2022 "}),
#"Changed Type2" = Table.TransformColumnTypes(#"Replaced Value2",{{"Employee ID", Int64.Type}, {"Name", type text}, {"Start Date", type date}, {"Division", type text}, {"Project", type text}, {"Job", type text}, {"Practice", type text}, {"Location", type text}, {"Grade", type text}, {"Org Division", type text}, {"Function", type text}, {"Department", type text}, {"Team", type text}, {"Manager", type text}, {"Employment Status", type text}, {"Annual Holiday Accural", Int64.Type}, {"Opening bal Jan 2012", Int64.Type}, {"Closing Hol Balance Dec 2012", Int64.Type}, {"Days Accrued2012", Int64.Type}, {"TOIL2012", Int64.Type}, {"Hols taken in2012 ", Int64.Type}, {"Buy Backs2012 ", Int64.Type}, {"Holiday Adjustments2012 ", Int64.Type}, {"Opening bal Jan 2013", Int64.Type}, {"Closing Hol Balance Dec 2013", Int64.Type}, {"Days Accrued2013", Int64.Type}, {"TOIL2013", Int64.Type}, {"Hols taken in2013 ", Int64.Type}, {"Buy Backs2013 ", Int64.Type}, {"Holiday Adjustments2013 ", Int64.Type}, {"Employee_Accrual_2013", Int64.Type}, {"Opening bal Jan 2014", Int64.Type}, {"Closing Hol Balance Dec 2014", Int64.Type}, {"Days Accrued2014", Int64.Type}, {"TOIL2014", Int64.Type}, {"Hols taken in2014 ", Int64.Type}, {"Buy Backs2014 ", Int64.Type}, {"Holiday Adjustments2014 ", Int64.Type}, {"Employee_Accrual_2014", Int64.Type}, {"Opening bal Jan 2015", Int64.Type}, {"Closing Hol Balance Dec 2015", Int64.Type}, {"Days Accrued2015", Int64.Type}, {"TOIL2015", Int64.Type}, {"Hols taken in2015 ", Int64.Type}, {"Buy Backs2015 ", Int64.Type}, {"Holiday Adjustments2015 ", Int64.Type}, {"Employee_Accrual_2015", Int64.Type}, {"Opening bal Jan 2016", Int64.Type}, {"Closing Hol Balance Dec 2016", Int64.Type}, {"Days Accrued2016", Int64.Type}, {"TOIL2016", Int64.Type}, {"Hols taken in2016 ", Int64.Type}, {"Buy Backs2016 ", Int64.Type}, {"Holiday Adjustments2016 ", Int64.Type}, {"Employee_Accrual_2016", Int64.Type}, {"Opening bal Jan 2017", Int64.Type}, {"Closing Hol Balance Dec 2017", Int64.Type}, {"Days Accrued2017", Int64.Type}, {"TOIL2017", Int64.Type}, {"Hols taken in2017 ", Int64.Type}, {"Buy Backs2017 ", Int64.Type}, {"Holiday Adjustments2017 ", Int64.Type}, {"Employee_Accrual_2017", Int64.Type}, {"Opening bal Jan 2018", Int64.Type}, {"Closing Hol Balance Dec 2018", Int64.Type}, {"Days Accrued2018", Int64.Type}, {"TOIL2018", Int64.Type}, {"Hols taken in2018 ", Int64.Type}, {"Buy Backs2018 ", Int64.Type}, {"Holiday Adjustments2018 ", Int64.Type}, {"Employee_Accrual_2018", Int64.Type}, {"Opening bal Jan 2019", Int64.Type}, {"Closing Hol Balance Dec 2019", Int64.Type}, {"Days Accrued2019", Int64.Type}, {"TOIL2019", Int64.Type}, {"Hols taken in2019 ", Int64.Type}, {"Buy Backs2019 ", Int64.Type}, {"Holiday Adjustments2019 ", Int64.Type}, {"Employee_Accrual_2019", Int64.Type}, {"Opening bal Jan 2020", Int64.Type}, {"Closing Hol Balance Dec 2020", Int64.Type}, {"Days Accrued2020", Int64.Type}, {"TOIL2020", Int64.Type}, {"Hols taken in2020 ", Int64.Type}, {"Buy Backs2020 ", Int64.Type}, {"Holiday Adjustments2020 ", Int64.Type}, {"Employee_Accrual_2020", Int64.Type}, {"Opening bal Jan 2021", Int64.Type}, {"Closing Hol Balance Dec 2021", Int64.Type}, {"Days Accrued2021", Int64.Type}, {"TOIL2021", Int64.Type}, {"Hols taken in2021 ", Int64.Type}, {"Buy Backs2021 ", Int64.Type}, {"Holiday Adjustments2021 ", Int64.Type}, {"Employee_Accrual_2021", Int64.Type}, {"Opening bal Jan 2022", Int64.Type}, {"Closing Hol Balance Dec 2022", Int64.Type}, {"Days Accrued2022", Int64.Type}, {"TOIL2022", Int64.Type}, {"Hols taken in2022 ", Int64.Type}, {"Buy Backs2022 ", Int64.Type}, {"Holiday Adjustments2022 ", Int64.Type}, {"Employee_Accrual_2022", Int64.Type}})
in
#"Changed Type2"

Hi @Holly454 

 

Thanks - how about the #"Transform File" function code?

Holly454
Frequent Visitor

Hi @ams1 , my Transform File code is here:

let
Source = Excel.Workbook(Parameter1, null, true),
#"Expanded Data" = Table.ExpandTableColumn(Source, "Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14", "Column15", "Column16", "Column17", "Column18", "Column19", "Column20", "Column21", "Column22", "Column23", "Column24"}, {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13", "Column14", "Column15", "Column16", "Column17", "Column18", "Column19", "Column20", "Column21", "Column22", "Column23", "Column24"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Data",{"Name"}),
#"Removed Top Rows" = Table.Skip(#"Removed Columns",2),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true])
in
#"Promoted Headers"

Hi @Holly454 

 

Sorry for the late reply.

 

I see, you've used the wizard to combine the files.

 

Can you please try the old-fashioned way below:

 

 

let
    Source = Folder.Files(REDACTED),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Content", "Name"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "CsvDocument", each Csv.Document([Content])),
    // try to standardize column names like this
    #"Added CsvDocumentStandardColumns" = Table.AddColumn(#"Added Custom", "CsvDocumentStandardColumns", each Table.RenameColumns([CsvDocument],{
        // add below all renames needed for all files
        {"Columnx", "AnotherColumnName"}, 
        {"ColumnY", "Something"}
        // ...
    // below will make sure you get no error case a rename does not apply
    }, MissingField.Ignore)) 
in
    #"Added CsvDocumentStandardColumns"

 

 

And then Expand...

ams1_1-1678790288831.png

 

...and then add all your subsequent steps.

 

IF/when you notice performance problems, please paste here your new query based on my initial code.

 

I edited my answer as I saw you have different column names... let's hope this works.

 

Please mark this as answer if it helped.

Holly454
Frequent Visitor

This worked beautifully - thank you so much!

Really happy it worked! 😊

 

P.S.: (also) Mark my previous reply with the code ☝️ as answer so that people can quickly find it 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors