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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

List.generate Issues

Hi Experts,

I am having an issue with the below code, It lays around the : result = List.Generate(
() => [runningTotal, additionalValuesList, 0],  I get a error message stating that i need a token']' but can not find a issue here.

 

Any help as always would be greatly appreciated 

 

Kind Regards

 

RunningTotal     AdditionalValues

40
-60
-164
-1910
-216
-353

 

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
AddValues = Table.AddColumn(Source, "AdjustedRunningTotal", each
let
runningTotal = [RunningTotal],
additionalValuesList = List.Buffer(Table.Column(Source, "AdditionalValues")),
result = List.Generate(
() => [runningTotal, additionalValuesList, 0],
each List.First(_) < 0,
each [
List.First(_) + List.First(List.Middle(_)),
List.RemoveFirstN(List.Middle(_), 1),
List.Last(List.Middle(_)) + List.First(List.Middle(_))
]
)
in
List.First(result)
)
in
AddValues

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

Hi, @Anonymous [runningTotal, additionalValuesList, 0] is record, record has fields, fields have names. Your record does not have field names. 

Next, each List.First(_) < 0 evaluates each item in the list that List.Generate generates. But wait, the very first item is record, not list.

And finally, even if you fix all bugs in your code then List.First(result) is going to give you ... the very first item which is your record defined in the very first line of List.Generate. 

You'd better explain here how would you like the column AdjustedRunningTotal to be calculated.  

View solution in original post

1 REPLY 1
AlienSx
Super User
Super User

Hi, @Anonymous [runningTotal, additionalValuesList, 0] is record, record has fields, fields have names. Your record does not have field names. 

Next, each List.First(_) < 0 evaluates each item in the list that List.Generate generates. But wait, the very first item is record, not list.

And finally, even if you fix all bugs in your code then List.First(result) is going to give you ... the very first item which is your record defined in the very first line of List.Generate. 

You'd better explain here how would you like the column AdjustedRunningTotal to be calculated.  

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors