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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

DAX - Return only one matching row?

This is kind of an odd request.

 

I have two tables, a fact table and a pivoted lookup table.

 

I have a [LookupKey] in my fact table that can have duplicate values. I have a similar [LookupKey] in the Pivoted Lookup table.

 

I need to be able to return a value from the pivoted lookup table to only the first or one of the matching rows in the fact table.

 

For example, my fact table can have two rows with the lookup key of "DogCat". The pivoted lookup table has a value of 1,500 for "DogCat". Is there a way I can return the 1,500 to just the first row or only one match in my fact table?

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create columns in 'fact table' like DAX below.

 

Rank = CALCULATE(COUNT('fact table'[LookupKey] ),FILTER(ALLSELECTED('fact table'),'fact table'[LookupKey] <=EARLIER('fact table'[LookupKey] )))
 

Matched value= IF('fact table'[Rank]=1, CALCULATE (FIRSTNONBLANK ('Pivoted Lookup table'[matched Value], 1 ),FILTER ( ALL ( 'Pivoted Lookup table'), 'Pivoted Lookup table'[LookupKey] ='fact table'[LookupKey] )), BLANK() )

 

Best Regards,

Amy

 

Community Support Team _ Amy

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

2 REPLIES 2
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may create columns in 'fact table' like DAX below.

 

Rank = CALCULATE(COUNT('fact table'[LookupKey] ),FILTER(ALLSELECTED('fact table'),'fact table'[LookupKey] <=EARLIER('fact table'[LookupKey] )))
 

Matched value= IF('fact table'[Rank]=1, CALCULATE (FIRSTNONBLANK ('Pivoted Lookup table'[matched Value], 1 ),FILTER ( ALL ( 'Pivoted Lookup table'), 'Pivoted Lookup table'[LookupKey] ='fact table'[LookupKey] )), BLANK() )

 

Best Regards,

Amy

 

Community Support Team _ Amy

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

Greg_Deckler
Community Champion
Community Champion

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490.

 

Should be able to use something like FIRSTNONBLANK and FILTER to achieve what you need or perhaps MAXX or MINX.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors