Forum Discussion
Append queries based on excel cell values.
I have some queries and I append all queries into a Master query.
SS23_LL_LP + AH23_LL_LP + SS24_LL_LP = MasterChartLL
But I want that MasterChartLL will be appended based on the Excel table.
My requirement:
I have an excel table like the below picture.
If the Excel chart is updated SS23, AW23 then,
MasterChartLL will append SS23_LL_LP + AH23_LL_LP
Or
If In Excel chart, is updated with SS23, and SS24 then,
MasterChartLL will append SS23_LL_LP + SS24_LL_LP
How can I dynamic append queries based on excel data?
Hi Anonymous
They say "eval is EVIL", but in PowerQuery it's an angel 👼!
Given:
...and TLSeasonFilter is:
WHEN MasterChartLL is:
let Source = TLSeasonFilter, #"Added WithSuffix" = Table.AddColumn(Source, "WithSuffix", each [Season] & "_LL_SP"), // ^^^^^^^^ - all have same suffix, right? #"Removed Other Columns" = Table.SelectColumns(#"Added WithSuffix", {"WithSuffix"}), TableToList = Table.ToList(#"Removed Other Columns"), listOfTables = List.Accumulate( TableToList, {}, (final, current) => List.Combine({final, {Expression.Evaluate(current, #shared)}}) ), ret = Table.Combine(listOfTables) // assumes all tables have same header in retThen you should get what you want - if I understood it correctly. 😉
Please mark this as ANSWER if it helped.
P.S.: currently the TLSeasonFilter controls what tables get appended. If you want SS24_LL_LP to be always present, just add it to the List.Accumulate seed: instead of "{}", use "{Expression.Evaluate("SS24_LL_SP", #shared)}"
7 Replies
- ams1Responsive Resident
Hi Anonymous
They say "eval is EVIL", but in PowerQuery it's an angel 👼!
Given:
...and TLSeasonFilter is:
WHEN MasterChartLL is:
let Source = TLSeasonFilter, #"Added WithSuffix" = Table.AddColumn(Source, "WithSuffix", each [Season] & "_LL_SP"), // ^^^^^^^^ - all have same suffix, right? #"Removed Other Columns" = Table.SelectColumns(#"Added WithSuffix", {"WithSuffix"}), TableToList = Table.ToList(#"Removed Other Columns"), listOfTables = List.Accumulate( TableToList, {}, (final, current) => List.Combine({final, {Expression.Evaluate(current, #shared)}}) ), ret = Table.Combine(listOfTables) // assumes all tables have same header in retThen you should get what you want - if I understood it correctly. 😉
Please mark this as ANSWER if it helped.
P.S.: currently the TLSeasonFilter controls what tables get appended. If you want SS24_LL_LP to be always present, just add it to the List.Accumulate seed: instead of "{}", use "{Expression.Evaluate("SS24_LL_SP", #shared)}"
- AnonymousNot applicable
From this step, this is not working. Before, all steps are working. I think, Need to change something. Please advise. Not an expert in M language. 😞
- ams1Responsive Resident
Hi Anonymous
Can you please share the error?