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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Porkey
Frequent Visitor

List.Generate shows an error but i cant find the e

Hi 

 

this is the error shown

Porkey_0-1648136971046.png

I then get a full table of results when i transform to a table (showing no errors in any rows (it works perfectly as intended)

 

Code for the list.generate is 

 

 

= List.Generate(
()=>[
RotaType = #"Rota_Data (2)"{CR}[RotaType],
RotaSlotType = #"Rota_Data (2)"{CR}[RotaSlotType],
Duration = #"Rota_Data (2)"{CR}[Duration],
Index = #"Rota_Data (2)"{CR}[Index],
CR = 0,
NR = 1,
EX = -1,
CRRotaName = #"Rota_Data (2)"{CR}[ROTA],
NRRotaName = #"Rota_Data (2)"{NR}[ROTA],
CRTime = #"Rota_Data (2)"{CR}[TimeStart],
NRTime = #"Rota_Data (2)"{NR}[TimeStart],
ActualPosition = 1
],

each [CR] < List.Max(#"Rota_Data (2)"[Index]),

each
if
[ActualPosition] <>1 and [CRRotaName] <> [NRRotaName]

then [
RotaType = #"Rota_Data (2)"{CR}[RotaType],
RotaSlotType = #"Rota_Data (2)"{CR}[RotaSlotType],
Duration = #"Rota_Data (2)"{CR}[Duration],
Index = #"Rota_Data (2)"{CR}[Index],
CR = [CR] +1,
NR = [NR] +1,
EX = [CR] ,
CRRotaName = #"Rota_Data (2)"{CR}[ROTA],
NRRotaName = #"Rota_Data (2)"{NR}[ROTA],
CRTime = #"Rota_Data (2)"{CR}[TimeStart],
NRTime = #"Rota_Data (2)"{NR}[TimeStart],
ActualPosition = [ActualPosition]+1

]
else [
RotaType = #"Rota_Data (2)"{CR}[RotaType],
RotaSlotType = #"Rota_Data (2)"{CR}[RotaSlotType],
Duration = #"Rota_Data (2)"{CR}[Duration],
Index = #"Rota_Data (2)"{CR}[Index],
CR = [CR] +1,
NR = [NR] +1,
EX = [EX] +1,
CRRotaName = #"Rota_Data (2)"{CR}[ROTA],
NRRotaName = #"Rota_Data (2)"{NR}[ROTA],
CRTime = [CRTime] + #"Rota_Data (2)"{EX}[Actual Duration],
NRTime = #"Rota_Data (2)"{NR}[TimeStart],
ActualPosition = [ActualPosition]+1
]


)

 

 

It looks through and adds a duration to the time of the next line based on whether or not its the same Rota or not (all the rota outputs is a start time)

 

I noticed the error when i expanded a merge into another query table.

 

The error shown on that table is 

An error occurred in the ‘DurationList’ query. Expression.Error: There weren't enough elements in the enumeration to complete the operation.
Details:
[Table]

 

Any help appreciated

"please ignore the ess, im just working on a copy so its gotten a bit messy"

 

1 ACCEPTED SOLUTION

Thank you for the advice it turned out to be 

 

each [CR] < List.Max(#"Rota_Data (2)"[Index]),

I needed to amend it to NR instead as CR did not reach the maximum value until one step after the end

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

I can't tell precisely where the problem is but I'm betting it's an off-by-one indexing error where you're trying to pull 

#"Rota_Data (2)"{CR}[ColName]

where CR is greater than the maximal index of Rota_Data (2).

Thank you for the advice it turned out to be 

 

each [CR] < List.Max(#"Rota_Data (2)"[Index]),

I needed to amend it to NR instead as CR did not reach the maximum value until one step after the end

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.