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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Random pick up of single column from a table depending on ranking (RANKX) and multiple slicers

Hi All

 

I am currently trying to generate random selected of names based on a RANKX dax calculating the higher net profit company, depending on "Size" and "Location" slicer. I would ideally like to show only 2 "Blind names" in a little table within the top 5 of my RANKX based on the following table: 

Blind name Real name Net profit Size Location 
AAAA                   10Small Germany 
BBB                   11Mid England 
CCC                   12Mid Netherlands 
DDD                   13Mid Germany 
EEE                   14Large England 
FFF                   15Large Netherlands 

I am currently using the following DAX measure to calculate the ranking dynamically: 

RANKX(
ALLSELECTED(Data_Benchmark),
CALCULATE(SUM('Data_Benchmark'[Net profit])),
,
DESC,
Dense
)
 
Does anyone has an idea how I could do it? Any help would be appreciated, many thanks!
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create calculated column.

Rand = INT(RAND()*1000)

2. Create measure.

Rank_Net profit =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[Net profit ])),,ASC,Dense)
Rank_Rand =
RANKX(
    FILTER(
    ALL('Table'),
    [Rank_Net profit]<=5),   
    CALCULATE(SUM('Table'[Rand])),,ASC,Skip)
Flag =
IF(
    [Rank_Net profit]<=5&&[Rank_Rand]<=2,1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1661909032519.png

4. Result:

vyangliumsft_1-1661909032521.png

If you need pbix, please click here.

Random pick up of single column from a table depending on ranking (RANKX) and multiple slicers.pbix

 

Best Regards,

Liu Yang

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
Anonymous
Not applicable

Hi  @Anonymous ,

Here are the steps you can follow:

1. Create calculated column.

Rand = INT(RAND()*1000)

2. Create measure.

Rank_Net profit =
RANKX(ALL('Table'),CALCULATE(SUM('Table'[Net profit ])),,ASC,Dense)
Rank_Rand =
RANKX(
    FILTER(
    ALL('Table'),
    [Rank_Net profit]<=5),   
    CALCULATE(SUM('Table'[Rand])),,ASC,Skip)
Flag =
IF(
    [Rank_Net profit]<=5&&[Rank_Rand]<=2,1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_0-1661909032519.png

4. Result:

vyangliumsft_1-1661909032521.png

If you need pbix, please click here.

Random pick up of single column from a table depending on ranking (RANKX) and multiple slicers.pbix

 

Best Regards,

Liu Yang

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

Anonymous
Not applicable

Thanks works fine for me

lbendlin
Super User
Super User

You can fudge it somehow with a second measure that runs another "random" RANKX over your top 5 items (by the way you can use TOPN() instead of RANKX() for that).  However, it is not really random, and too random at the same time. So you will have scenarios when more or fewer than your choice of two random accounts will be returned.

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.