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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
akshansh99
New Member

DAX measure to get top unique rows

Hey community!

I am trying to get the top rows from a table to use in my measure and the requirnments are:

 

1) user will select how many rows they want to retrieve based on a single select numerical slicer

2) the table has a date column which consists duplicate values, the result set should contain UNIQUE values which are less than or equal to the date selected in the slicer(single select dropdown)

 

I have tried almost every table manipulation function but i am not able to fetch only the unique values from the table i will share the codes i have tried and if you can suggest a better approach or guide me where i am going wrong that would be very helpful!

 

1) TOPN(

 24,
 CALCULATETABLE(
  DISTINCT(ExchangeRate),
  ExchangeRate[AsOf] <= date(2022,10,11)
 ), ExchangeRate[AsOf],DESC )
 
2)TOPN( 24, CALCULATETABLE( DISTINCT( SUMMARIZE( ExchangeRate, ExchangeRate[AsOf], ExchangeRate[ID], ExchangeRate[ToCurrencyID] ) ), ExchangeRate[AsOf] < <= date(2022,10,11) ), ExchangeRate[AsOf],DESC )
 
in these approaches i think the ID column does not allow me to filter the unique date values becuase it has a unique values in all the rows, i might be wrong here but that's what i understood
 
3) CALCULATETABLE(TOPN(24,CALCULATETABLE(VALUES(ExchangeRate[AsOf]),ExchangeRate[AsOf]<=date(2022,10,11)),ExchangeRate[AsOf]))
This approach doesn't give me the whole table it just gives me a single column table
 
4) ADDCOLUMNS(
CALCULATETABLE(TOPN(23,CALCULATETABLE(VALUES(ExchangeRate[AsOf]),ExchangeRate[AsOf]<=date(2022,10,11)),ExchangeRate[AsOf])), "ID",CALCULATE(MAXA(ExchangeRate[Id])))
 
 i have tried adding column to my single column table but this doesn't give a row level context to my measure and then because of that the matrix visual shows result like this 
akshansh99_0-1675753161416.png

 

 my end goal here is to show these stressed rates by ID or by DATE, something like this
akshansh99_1-1675753947006.png

 

 

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @akshansh99,

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Notice: please remove the sensitive data before share.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.