Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi all,
I'm attempting to use List.Accumulate with a Table Function to end up with a single combined table from the results.
So data looks like this:
Project No | Data Type | RawTable |
01 | A | <Table> |
02 | A | <Table> |
03 | B | <Table> |
I have a function (FnIterator) that processed the data in [RawTable] and produces a table as a result.
I've written a query that looks like this, but I'm getting stuck on the syntax of the acculator function in List.Accumulate. (this doesn't work currently, I get an error that suggests I'm not properly using 'each').
let
FilterValue = "A",
#"Filtered Rows" = Table.SelectRows(SourceQuery, each ([Data Type] = FilterValue)),
#"ListAccumulate" =
List.Accumulate(
[Project No],
null,
(state, current) =>
Table.Combine(
{
state,
FnIterator(
Record.Field(
current,
[RawTable]
),
FilterValue
)
}
)
)
in
#"ListAccumulate"
The desired result is a table that combines the results from the Raw Data column of Rows 01 and 02.
The FnIterator function takes two arguements, a Table, and Filtervalue, which is passed from the beginning of the query.
Solved! Go to Solution.
In case anyone happens upon this thread, or cares. Ultimatly I discovered that my understanding of List.Accumulate was generally correct, my error was in the Function being called, where it was effectively attempting to drill down an 'extra' time, where as the code above effectively was providing the correct level of drill down. I didn't happen upon this solution until thoroughly convincing myself (thanks Youtube) that I correctly understood 'each' and '_'. After that, and with some further testing, experimentation I realized what was going on.
As they say, if you're troubleshooting yourself, you're just workin'. 🙂
Also for the record the final code looks something like this, including proper handling for the 'seed' context of the Accumulate function:
let
FilterValue = "value",
#"Filtered Rows" = Table.SelectRows(ProjectData, each ([Data Type Parameter] = FilterValue)),
//invoke the custom function to transform the tables as a NewColumn (maybe I could just transform the column in place?). Might need some error handling for the possibility of null tables or such, not sure.
#"Invoked Custom Function" =
Table.AddColumn(
#"Filtered Rows",
"FnIterator",
each FnIterator([DetailedData], FilterValue
)
),
//isolate the table from the first row to use a seed
#"IsolateFirstTable"= #"Invoked Custom Function"{0}[FnIterator],
//now combine all of the tables, starting with the seed table
#"ListAccumulate" =
List.Accumulate(
//need to remove the first item from our list, since we're using it as our seed value
List.RemoveFirstN(
#"Invoked Custom Function"[FnIterator],
1
),
#"IsolateFirstTable",
(current, state)=>
//this becomes super simple, because we're only combining the list of things we already transformed
Table.Combine({current, state})
),
#"Removed Columns" = Table.RemoveColumns(ListAccumulate,{"id"})
in
#"Removed Columns"
In case anyone happens upon this thread, or cares. Ultimatly I discovered that my understanding of List.Accumulate was generally correct, my error was in the Function being called, where it was effectively attempting to drill down an 'extra' time, where as the code above effectively was providing the correct level of drill down. I didn't happen upon this solution until thoroughly convincing myself (thanks Youtube) that I correctly understood 'each' and '_'. After that, and with some further testing, experimentation I realized what was going on.
As they say, if you're troubleshooting yourself, you're just workin'. 🙂
Also for the record the final code looks something like this, including proper handling for the 'seed' context of the Accumulate function:
let
FilterValue = "value",
#"Filtered Rows" = Table.SelectRows(ProjectData, each ([Data Type Parameter] = FilterValue)),
//invoke the custom function to transform the tables as a NewColumn (maybe I could just transform the column in place?). Might need some error handling for the possibility of null tables or such, not sure.
#"Invoked Custom Function" =
Table.AddColumn(
#"Filtered Rows",
"FnIterator",
each FnIterator([DetailedData], FilterValue
)
),
//isolate the table from the first row to use a seed
#"IsolateFirstTable"= #"Invoked Custom Function"{0}[FnIterator],
//now combine all of the tables, starting with the seed table
#"ListAccumulate" =
List.Accumulate(
//need to remove the first item from our list, since we're using it as our seed value
List.RemoveFirstN(
#"Invoked Custom Function"[FnIterator],
1
),
#"IsolateFirstTable",
(current, state)=>
//this becomes super simple, because we're only combining the list of things we already transformed
Table.Combine({current, state})
),
#"Removed Columns" = Table.RemoveColumns(ListAccumulate,{"id"})
in
#"Removed Columns"
bumping this to the top of the list... 🙂
=Table.Combine(List.Transform(PreversStepName[RawTable],each Table.FisrtN(_,2)))
@wdx223_Daniel thank you for replying, but having a little trouble understanding the suggested course of action.
= Table.Combine(
List.Transform(
PreversStepName[RawTable], //I assume this was shorthand for 'Previous Step Name'
each Table.FisrtN(_,2) //'2' to get first two rows of the table which happen to be correct rows based on the filter value?
)
)
Where, how is the Function called that needs to iterate on the Table Record embedded in the Column [RawTable]?
Thank you,
-Robert
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
14 | |
13 | |
12 | |
12 | |
12 |