cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ciriatto
New Member

How to reference a table random values in Power Query?

Hello everyone,

 

I have been working on a project where I create random data using the built-in functions of Power Query (Number.RandomBetween()). After I finished this table I created a reference to it but the second table apparently does not copy it's values but re-executes the Query and  generates new data. I need that the second table be exactly equal to the first table otherwise the results will be inconsistent. Is there a workaround for that? 

 

P.S. : I tried loading the data of the first table into excel and using as the source for the second one, but that didn't work.

 

Thanks for the help.

1 ACCEPTED SOLUTION
otis_pc
Regular Visitor

Do you need your first table to continually generate random numbers? If not, you could try seeding your random values in the first table. (And since that one won't recalculate when the second one references it, the numbers should stay put.)

 

I needed to create a stable table of random numbers and first tried the Number.RandomBetween() but it changed constantly, so I used this line instead:

 

 

 

AddRandom = Table.FromColumns({List.Transform(List.Random(57,nSeed), each Number.RoundUp(_ *5))}, {"Strength (Random)"})

 

 

 

That generated a list of 57 numbers between 1 and 5, and then created a single column table of 57 rows containing the numbers 1 through 5.

 

I'm pretty sure RADACAD is where I picked that trick up from: Generate Random List of Numbers in Power BI Using Power Query

 

If the first table needs to continually regenerate, then I can't help on this one.

View solution in original post

3 REPLIES 3
otis_pc
Regular Visitor

Do you need your first table to continually generate random numbers? If not, you could try seeding your random values in the first table. (And since that one won't recalculate when the second one references it, the numbers should stay put.)

 

I needed to create a stable table of random numbers and first tried the Number.RandomBetween() but it changed constantly, so I used this line instead:

 

 

 

AddRandom = Table.FromColumns({List.Transform(List.Random(57,nSeed), each Number.RoundUp(_ *5))}, {"Strength (Random)"})

 

 

 

That generated a list of 57 numbers between 1 and 5, and then created a single column table of 57 rows containing the numbers 1 through 5.

 

I'm pretty sure RADACAD is where I picked that trick up from: Generate Random List of Numbers in Power BI Using Power Query

 

If the first table needs to continually regenerate, then I can't help on this one.

That solved my problem. Thanks a lot!

 

BA_Pete
Super User
Super User

Hi @ciriatto ,

 

Yes, this is normal behaviour for Power Query. Each query will refresh, and each function will be evaluated, independently.

If you have fewer than 3,000 cells worth of data, you could copy the entire first table and paste it into the 'Enter Data' area, then duplicate this table?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors