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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
rpiboy_1
Resolver I
Resolver I

struggling with List.Accumulate and a Table Function

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 NoData TypeRawTable
01A<Table>
02A<Table>
03B<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.

1 ACCEPTED SOLUTION
rpiboy_1
Resolver I
Resolver I

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"



View solution in original post

4 REPLIES 4
rpiboy_1
Resolver I
Resolver I

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"



rpiboy_1
Resolver I
Resolver I

bumping this to the top of the list... 🙂

wdx223_Daniel
Super User
Super User

=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

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors