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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Dicken
Responsive Resident
Responsive Resident

Function within List.Generate

Hi, 

I have to grouped accumulations ; 
A ; which does not work ; 
= Table.Group(Source, {"Name", "Item"},
                      {{"Count", each
                             List.Generate( ()=> [ x = 0 , y = [Unit] {0} ] ,
                                                  each [x] < List.Count( [Unit] ) ,
                                                    each [ x = 0 , y = [y] + [Unit] {x} ] ,
                                                   each [y] )
                                    }  } )

and B; which does; 
Table.Group(Source, {"Name", "Item"}, {{"Count", (i)=>
                                                            List.Generate( ()=> [ x = 0 , y = i[Unit] {0} ],
                                                                                 each [x] < List.Count( i [Unit] ) ,
                                                                                 each [ x = [x] + 1, y = [y] + i [Unit] {x} ] ,
                                                                               each [y] )
                                                                       }} )
As can be seen if defined the  function (i)=> in the second, so is the first refering to an 'outside' table, while the 'each' in 
generate is specifically whats going on within the List.Generate , so where both are each it gets confused and causes an error 
or something like that ? 

  Rchard. 

2 ACCEPTED SOLUTIONS
ronrsnfld
Super User
Super User

You have it correct.

View solution in original post

ZhangKun
Super User
Super User

The each keyword is a syntax sugar, which is a shorthand form of "(_) =>". In the first case, only the each keyword is used. The program will find whether there is a Unit column in the variable (identifier) ​​named "_" in the nearest layer.

The key point is:

  • The function in the first parameter has no parameters, so the Unit column can be found (there is no variable named _ at the current level, so it will be looked for outside).
  • The next three parameters all use the each keyword, which uses _ as the name, so [Unit] in them cannot find the Unit column (looking for the nearest variable named _).

    ZhangKun_0-1745086798620.png

View solution in original post

3 REPLIES 3
ZhangKun
Super User
Super User

The each keyword is a syntax sugar, which is a shorthand form of "(_) =>". In the first case, only the each keyword is used. The program will find whether there is a Unit column in the variable (identifier) ​​named "_" in the nearest layer.

The key point is:

  • The function in the first parameter has no parameters, so the Unit column can be found (there is no variable named _ at the current level, so it will be looked for outside).
  • The next three parameters all use the each keyword, which uses _ as the name, so [Unit] in them cannot find the Unit column (looking for the nearest variable named _).

    ZhangKun_0-1745086798620.png

ronrsnfld
Super User
Super User

You have it correct.

Dicken
Responsive Resident
Responsive Resident

Thanks, it took a while for the penny to drop when I kept getting an 
error, at first I used a let statement, and named the [Units]  and then I could use the name. 
in  generate. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.