Forum Discussion
To Help understand DAX MEASURE | RANKX | Filter Context | Row Context
- 3 years ago
Please try
M1 =SUMX(VALUES(FactMemberQualityMeasures[QMID]),VAR CurrentQMID =FactMemberQualityMeasures[QMID]RETURNSUMX (CALCULATETABLE(VALUES ( FactMemberQualityMeasures[MemberID] )),VAR QM2_data =CALCULATETABLE(FactMemberQualityMeasures,FactMemberQualityMeasures[QMID] IN { 10, 11, 12, 13 },ALL ( DimQualityMeasures[QMID]))VAR QM2_Dataset =TOPN ( 1, QM2_data, FactMemberQualityMeasures[RISK_RANK], ASC )VAR maxQMID =MAXX(QM2_Dataset, FactMemberQualityMeasures[QMID])RETURNIF(CurrentQMID = maxQMID,SUMX ( QM2_Dataset, FactMemberQualityMeasures[DENOMINATOR] ))))
Hi selvakumarr
You missing the context transition inside the ADDCOLUMNS function. You may try the following, however, this is not the optimum method to accomplish this result.
=
VAR QM2_Dataset =
ADDCOLUMNS (
QM2_data,
"Rn",
VAR QM2_data =
FILTER (
CALCULATETABLE ( FactPatient ),
FactPatient[QMID] IN { 10, 11, 12, 13 }
)
RETURN
RANKX ( QM2_data, FactPatient[Ranked_Risk],, ASC, SKIP )
)
RETURN
SUMX ( FILTER ( QM2_Dataset, [Rn] = 1 ), FactPatient[NUMERATOR] )
hi tamerj1 , Thanks for the quick reply, this is giving me correct result for one month, but if I select multiple months the numbers are not as expected because the measure is evaluating Rank for each month individually and then sums up at the end and it is not what I wanted.
If multiple months are selected I want to pick only one record per patient with the lowest ranked_risk and then do the sum of numerator.
- tamerj13 years agoCommunity Champion
Hi selvakumarr
In this case please try= SUMX ( VALUES ( FactPatient[Member ID] ), VAR QM2_data = FILTER ( CALCULATETABLE ( FactPatient ), FactPatient[QMID] IN { 10, 11, 12, 13 } ) VAR QM2_Dataset = TOPN ( 1, QM2_data, FactPatient[Ranked_Risk], ASC ) RETURN SUMX ( QM2_Dataset, FactPatient[NUMERATOR] ) )- selvakumarr3 years agoFrequent Visitor
Hi tamerj1 , Sorry, I was just over the moon when I saw the Numbers are matching for each month, Multiple months and all months (Data is matching for all Scenarios), but When I drill down to QMID level, the sum of Individual numbers are higher than Total like below
I could not debud betwwen this row_context and filter context. Could you me understand why is this happening?
- tamerj13 years agoCommunity Champion
Try what you get out of this. It should give better idea. Deactivate total before doing that
=
CONCATENATEX (
VALUES ( FactPatient[Member ID] ),
VAR QM2_data =
FILTER (
CALCULATETABLE ( FactPatient ),
FactPatient[QMID] IN { 10, 11, 12, 13 }
)
VAR QM2_Dataset =
TOPN ( 1, QM2_data, FactPatient[Ranked_Risk], ASC )
RETURN
CONCATENATEX ( QM2_Dataset, FactPatient[NUMERATOR], " - " ),
UNICHAR ( 10 )
)