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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Porkey
Regular 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors