Search code examples
powerbidaxdaxstudio

how to get top 1 Vendor name based on spends with application of slicers in DAX?


I want to get top 1 vendor name by spend which I am getting through

Top 1 Vendor = CALCULATE(SELECTEDVALUE(PSL[VName]),TOPN(1,ALL(PSL),[Spend],DESC))

VName = vendor name
PSL = table name
Spend = another measure

This is working alright and fetching the top vendor name however if I put a Country and Category slicer, the Vendor name doesn't change accordingly. How do I make my measure dynamic to slicer selected values?

I did try one more thing but that is also not working -

CALCULATE(SELECTEDVALUE(PSL[VName]),TOPN(1,ALLEXCEPT(PSL,PSL[Category]),[Spend],DESC))

Country will come from another table.

Any help is appreciated


Solution

  • I did this and it worked-

    CALCULATE(SELECTEDVALUE(PSL[VName]),TOPN(1,ALL(PSL[VName]),[Spend]),VALUES(PSL[VName]))