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! Learn more

Reply
Anonymous
Not applicable

Generating a random sequence of numbers

Hi all,

I'd like to know if there's a way in M to generate a random sequence of numbers of predefined lenght in each row

I need this because I'm creating a demo of a report and I'd like to add the phone number of the users in a table but I have to randomly generate it as I cannot show real people telephone numbers 

Therefore the requirement is to generate, in each row, a random sequence of 8 numbers, with as less effort as possible 

Thanks

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

here it is with effort zero (from you 😁)

 

 

let
telnum= (digits,seed) =>Text.Combine(List.Transform(List.Random(digits,seed), each Text.From(Number.RoundDown(_*10)))),
lst=List.Transform({1..20}, each telnum(8,_) )
in
lst

 

View solution in original post

v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

You may try what is suggested by @Anonymous . I created data to reproduce your scenario. The pbix file is attached in the end.

 

Table:

d1.png

 

Here is the codes in 'Advanced Editor'.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YlWcgKTzmDSBUy6KsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    temp = (digits,seed) =>Text.Combine(List.Transform(List.Random(digits,seed), each Text.From(Number.RoundDown(_*10)))),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each List.Transform({1..20}, each temp(8,_)){[Index]}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

Result:

d2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

You may try what is suggested by @Anonymous . I created data to reproduce your scenario. The pbix file is attached in the end.

 

Table:

d1.png

 

Here is the codes in 'Advanced Editor'.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YlWcgKTzmDSBUy6KsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    temp = (digits,seed) =>Text.Combine(List.Transform(List.Random(digits,seed), each Text.From(Number.RoundDown(_*10)))),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each List.Transform({1..20}, each temp(8,_)){[Index]}),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

Result:

d2.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

here it is with effort zero (from you 😁)

 

 

let
telnum= (digits,seed) =>Text.Combine(List.Transform(List.Random(digits,seed), each Text.From(Number.RoundDown(_*10)))),
lst=List.Transform({1..20}, each telnum(8,_) )
in
lst

 

Greg_Deckler
Community Champion
Community Champion

=Number.RandomBetween()

https://docs.microsoft.com/en-us/powerquery-m/number-randombetween



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Kudoed Authors