Forum Discussion
Custom Functions and issues with extreme long load time.
Thanks Anonymous
Here's an example of the code.
Where i get my raw data, filter the data, sum the filtered data and add some extra columns and lastly i then append the summed data to the raw data. This approach gives me the desired result i'm looking for in the desktop preview, but when i apply the changes/steps, the load just keeps on for hours. What am i missing?
(File) =>
let
Source = (File),
// Function to transform data based on a list of codes and parameters, and append the result to the source data
TransformGroup = (source as table, codes as list, newCode as text, newAccount as number, newDescription as text) as table =>
let
FilteredRows = Table.SelectRows(source, each List.Contains(codes, [Code1])),
GroupedRows = Table.Group(FilteredRows, {"Date"}, {{"Amount", each List.Sum([Amount]), type nullable number}}),
AddedColumns = Table.AddColumn(GroupedRows, "Code1", each newCode),
AddedCode2 = Table.AddColumn(AddedColumns, "Code2", each newCode),
AddedAccount = Table.AddColumn(AddedCode2, "Account_No", each newAccount),
AddedCompany = Table.AddColumn(AddedAccount, "Company", each "Company XYZ"),
AddedDescription = Table.AddColumn(AddedCompany, "Description", each newDescription),
ChangedType = Table.TransformColumnTypes(AddedDescription, {{"Account_No", Int64.Type}, {"Code1", type text}, {"Code2", type text}, {"Company", type text}}),
AppendedResults = Table.Combine({source, ChangedType})
in
AppendedResults,
// Process each group and keep appending to source
B100 = TransformGroup(Source, {"B10", "B20"}, "B100", 1, "Revenue"),
B200 = TransformGroup(B100, {"B50", "B100"}, "B200", 2, "Gross Profit"),
B300 = TransformGroup(B200, {"B150", "B200"}, "B300", 3, "Operating Profit"),
B400 = TransformGroup(B300, {"B250", "B300"}, "B400", 4, "Net Profit"),
D100 = TransformGroup(B400, {"D10", "D20", "D30"}, "D100", 10, "Current Assets"),
D200 = TransformGroup(D100, {"D50", "D100"}, "D200", 11, "Total Assets"),
D300 = TransformGroup(D200, {"D90", "D100"}, "D300", 12, "Liabilities"),
D400 = TransformGroup(D300, {"D200", "D300"}, "D400", 13, "Equity and Liabilities"),
Result = D400
in
Result