Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
let
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)
Solved! Go to Solution.
@Anonymous 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
@Anonymous 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 )
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
14 | |
13 | |
12 | |
12 | |
12 |