New Member
March 8, 2021
I am working on the Covid-19 vaccination effort and I could really use some help as I do not normally write code. I am using power query to load data from a set of CSV files, but the data refreshes are taking too long. I have turned off privacy settings, stopped background refresh, and combined all my queries into one query (below) to speed things up, but its still taking 4 minutes to load 600k lines (500MB of CSV data).
I want to use table.buffer to speed this up, but I can not figure out where to put it. If I try putting it in front of the source like this table.buffer(Source = Folder.Files("T:\Restricted\2_Vaccination_Project\Reporting\Simon\Power Pivot Import")) then I get an error message "Token Equal Expected".
Please tell me where I am supposed to put table.buffer (please be explicit, I have not used power query before today)!
let
WithAddedKey =
Table.AddKey(
#"Names",
{"User Name"},
true),
Source = Folder.Files("T:\Restricted\2_Vaccination_Project\Reporting\Simon\Power Pivot Import"),
#"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([Extension], ".csv")),
#"Filtered Hidden Files2" = Table.SelectRows(#"Filtered Rows", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function2" = Table.AddColumn(#"Filtered Hidden Files2", "Transform File from Grab&Clean Data", each #"Transform File from Grab&Clean Data"([Content])),
#"Renamed Columns2" = Table.RenameColumns(#"Invoke Custom Function2", {"Name", "Source.Name"}),
#"Removed Other Columns2" = Table.SelectColumns(#"Renamed Columns2", {"Source.Name", "Transform File from Grab&Clean Data"}),
#"Expanded Table Column2" = Table.ExpandTableColumn(#"Removed Other Columns2", "Transform File from Grab&Clean Data", Table.ColumnNames(#"Transform File from Grab&Clean Data"(#"Sample File (2)"))),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Table Column2",{"Team", "Source.Name", "Invitee Name", "Invitee Time Zone", "Invitee accepted marketing emails", "Event Type Name", "Location", "Canceled By", "Cancellation reason", "Question 1", "Question 2", "Question 6", "Response 6", "Question 7", "Response 7", "UTM Campaign", "UTM Source", "UTM Medium", "UTM Term", "UTM Content", "Salesforce UUID", "Event Price", "Payment Currency", "Guest Email(s)", "Response 2", "Question 3", "Response 3", "Question 4", "Response 4", "Question 5", "Response 5"}),
#"Split Start Date/Time" = Table.SplitColumn(Table.TransformColumnTypes(#"Removed Columns", {{"Start Date & Time", type text}}, "en-US"), "Start Date & Time", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Start Date & Time.1", "Start Date & Time.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Start Date/Time",{{"Start Date & Time.1", type date}, {"Start Date & Time.2", type time}}),
#"Split Created Date Time" = Table.SplitColumn(Table.TransformColumnTypes(#"Changed Type1", {{"Event Created Date & Time", type text}}, "en-US"), "Event Created Date & Time", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, false), {"Event Created Date & Time.1", "Event Created Date & Time.2"}),
#"Changed Type2" = Table.TransformColumnTypes(#"Split Created Date Time",{{"Event Created Date & Time.1", type date}, {"Event Created Date & Time.2", type time}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type2",{{"Response 1", "Phone 2"}, {"Start Date & Time.1", "Start Date"}, {"Start Date & Time.2", "Start Time"}, {"Event Created Date & Time.1", "Created Date"}, {"Event Created Date & Time.2", "Created Time"}}),
#"Removed Duplicates" = Table.Distinct(#"Renamed Columns"),
#"Merged Queries" = Table.NestedJoin(#"Removed Duplicates", {"User Name"}, Names, {"User Name"}, "Names", JoinKind.LeftOuter),
#"Expanded Names" = Table.ExpandTableColumn(#"Merged Queries", "Names", {"Clean Name"}, {"Clean Name"}),
#"Remove Unclean Name" = Table.RemoveColumns(#"Expanded Names",{"User Name"}),
#"Reordered Columns" = Table.ReorderColumns(#"Remove Unclean Name",{"Clean Name", "Invitee First Name", "Invitee Last Name", "Invitee Email", "Text Reminder Number", "Phone 2", "Start Date", "Start Time", "End Date & Time", "Created Date", "Created Time", "Canceled"}),
#"Uppercased Text" = Table.TransformColumns(#"Reordered Columns",{{"Canceled", Text.Upper, type text}}),
#"Filtered Rows1" = Table.SelectRows(#"Uppercased Text", each [Canceled] = "FALSE"),
#"Filtered Rows2" = Table.SelectRows(#"Filtered Rows1", each [Clean Name] <> "Test"),
#"Grouped Rows" = Table.Group(#"Filtered Rows2", {"Clean Name", "Start Date", "Created Date"}, {{"Count", each Table.RowCount(_), type number}})
in
#"Grouped Rows"
VIP
Trusted Members
December 7, 2016
Hello,
You need to put the Table.Buffer after the equal sign, as shown below.
This post has been linked to previously, so take a look. It is not always so that buffering the data improves the query load time.
Source = Table.Buffer(Folder.Files("T:\Restricted\2_Vaccination_Project\Reporting\Simon\Power Pivot Import"))
Br,
Anders
New Member
March 8, 2021
It looks like buffering the source won't help me because its a folder not a file. How do I get it to buffer each file in the folder, not the folder itself? Also I tried as you suggested, buffering a few different steps in the query (see below for an example) but when I did that the query would never finish refreshing (it loaded all the data, then just sat there doing nothing).
thebufferedTable = table.buffer(#"Invoke Custom Function2")
October 5, 2010
Hi Simon,
The use of Table.Buffer isn't very well explained by Microsoft. Sometimes it makes things quicker, sometimes it doesn't. In your case as you are loading files from a folder, there's no easy way to buffer each file. And there's no guarantee that doing that would makes things significantly quicker anyway.
Without actually having the code and files to hand for testing, it makes it difficult to pinpoint the issue.
I do see that you have a Merge in you steps, and a Grouping. Both can affect performance.
Your Merge is with another table called Names that we don't know anything about. What's in that? Where is it getting its data from?
What I would do is work through the query step by step until you hit the step that slows it down.
Start with #"Merged Queries". Copy your original query into another file then remove all steps from #"Merged Queries" down. Run that query. How long does it take? Then add #"Merged Queries" and repeat for every step.
You could try buffering both tables in the merge like this
#"Merged Queries" = Table.NestedJoin(Table.Buffer(#"Removed Duplicates"), {"User Name"}, Table.Buffer(Names), {"User Name"}, "Names", JoinKind.LeftOuter)
Other things to consider. You're loading the data from a network drive, try moving the files to a local drive and see if that speeds things up.
Regards
Phil
1 Guest(s)