Forum Discussion
colacan
Resolver II
5 years agoSelecting rows with highest value within group form virtual Table
Hi, Curetnly I have ID (duplicated) column only (Group column does not matter) . Starting from this column I want to create a table as below ID Group Rand_Num Max_Rand_ID 1 ...
Nathaniel_C
Community Champion
5 years agoHi colacan ,
So the way the Rand() works, I was not able to use it in a measure and select that value as highest. I tried it in Power Query as well, but that did not work either. So I created a table similiar to yours then added a Calculated Column using DAX, finally creating two measures, one that fills in every row with the highest value for each ID, and the second which fills in only if it is the highest value for that ID.
Max Rand =
VAR _curID =
MAX ( 'rand'[ID] )
VAR _calc =
CALCULATE (
MAX ( 'rand'[RANDOM] ),
FILTER ( ALLEXCEPT ( 'rand', 'rand'[ID] ), MAX ( 'rand'[ID] ) = _curID )
)
RETURN
_calc
=============================
Max Rand with highest value only =
VAR _curID =
MAX ( 'rand'[ID] )
VAR _curRand =
MAX ( 'rand'[RANDOM] )
VAR _calc =
CALCULATE (
MAX ( 'rand'[RANDOM] ),
FILTER ( ALLEXCEPT ( 'rand', 'rand'[ID] ), MAX ( 'rand'[ID] ) = _curID )
)
RETURN
IF ( _calc = _curRand, _curRand )
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel