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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Add a value to random rows with specified quantity

Hi everyone! Is there a way to add a string of text to random rows with specified quantity? 

The "Sample" column below is what I want to achieve.

In this example, there are 4 rows with Red color, and the sampling % for red is 50%. Thus, for 2 random rows with red color (50% of 4) the text "for sampling" should be added.

 

Unit #ColorSampling %SampleOccurenceRequired Sampling
1Red50% 42
2Blue30%For sampling11
3Black25%For sampling11
4Red50%For sampling42
5Red50% 42
6Red50%For sampling42

 

So far I have added a column for occurrence count

Occurence = COUNTX(FILTER('Unit', EARLIER ('Unit'[Color] ) = 'Unit'[Color]),'Unit'[Color])

 

then multiplying it with the % to get the required number of sampling rounded up

Required Sampling = ROUNDUP('Unit'[Sampling %]*'Unit'[Occurence],0)

 

but I can't figure out how to implement the required # of sampling to random rows

or if there's a way to create non-repeating random numbers 

 

Thanks in advance!

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

2 REPLIES 2
Ahmedx
Super User
Super User

Screen Capture #832.pngScreen Capture #833.png

Anonymous
Not applicable

I was able to find a workaround for now by adding an index column then creating a column with the following formula :

Sampling Index = rankx(
    FILTER('Unit',EARLIER('Unit'[Color])='Unit'[Color]
         &&EARLIER('Unit'[Unit #])='Unit'[Unit #]),
        'Unit'[Index])
 
and then the Sample column would be
Sample = if('Unit'[Sampling Index]<='Unit'[Required Sampling],"For sampling",BLANK())
 
not sure if this only gets the first x for sampling, but I checked and it doesn't necessarily get the data in the same order as the raw data so this may work.
 
any other ideas are still welcome 🙂

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.