cancel
Showing results for
Did you mean:

## I dont understand properly how List.Generate() works

``````let
my_function = () => "Test",
my_list = List.Generate(
()=>[x=1], // Failr here with: "ExpressionError: The name 'x' wasn't recogniced. Make sure it's spelled correctly."
each [x]<101,
each [x=x+1],
each Number.Round(Number.RandomBetween(1,101),0)
)
in
my_list``````

Im just trying to create a list with length 100 filled with random numbers from 1 to 100. I wanna know why It doesn´t work.

this is the example from the docs I was looking at before:

``````List.Generate(
() => [x = 1, y = {}],
each [x] < 10,
each [x = List.Count([y]), y = [y] & {x}],
each [x]
)``````

You can check that example at (https://learn.microsoft.com/en-us/powerquery-m/list-generate)

2 REPLIES 2

@iarenas The issue is at the third argument of List.Generate, when incrementing you need to consider that the current iterated value is a record so you need to use each [x= [x]+1 ]

Complete code:

``````let
my_list =
List.Generate (
() => [ x = 1 ],
each [x] < 101,
each [ x = [x] + 1 ],
each Number.Round ( Number.RandomBetween ( 1, 101 ), 0 )
)
in
my_list``````

If there isn't any other logic that you are going to use in List.Generate then you can also try List.Trasnform

``````=
List.Transform (
{ 1.. 100 },
each Number.Round ( Number.RandomBetween ( 1, 101 ), 0 )
)``````

Thanks a lot

Announcements

#### Celebrating the May Super User of the Month: Laurens Martens

@LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!

#### Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!