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
Gingerjeans88
Helper IV
Helper IV

Lookup value from related table based on a condition in another column in the related table

Hi all,

 

I have two related tables, one called Quote and the other Quote History. They are related with cardinality many:1 (Many Quote History items to one Quote). 

 

Quote

QUOTE IDCUSTOMER 
Q123Test Customer
Q456Example Client

 

Quote History

QUOTE IDSTAGESTAGE DURATION (MINUTES)
Q1231) Quote Request5
Q1232) Shipping Estimate7
Q4561) Quote Request1
Q4562) Shipping Estimate13

 

I want to lookup and return, in the Quote table, the Stage Duration for the Quotes in each stage, ie. achieve the below. Essentially, 'where stage =  1) quote request, display the value in stage duration for that quote id).

 

QUOTE IDSTAGE 1 DURATIONSTAGE 2 DURATION
Q12357
Q456113

 

I tried 'related(column name) but as I am wanting the calculated column on the 'one' side and not the 'many' side, this doesn't seem possible and I am at a loss? This should be so simple. Please help I am desperate to complete this by tomorrow!

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

These calculated column formulas work

=CALCULATE(MIN(quote_history[STAGE DURATION (MINUTES)]),FILTER(quote_history,quote_history[STAGE]="1) Quote Request"&&quote_history[QUOTE ID]=EARLIER(Quote[QUOTE ID])))
=CALCULATE(MIN(quote_history[STAGE DURATION (MINUTES)]),FILTER(quote_history,quote_history[STAGE]="2) Shipping Estimate"&&quote_history[QUOTE ID]=EARLIER(Quote[QUOTE ID])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

16 REPLIES 16
Ashish_Mathur
Super User
Super User

Hi,

These calculated column formulas work

=CALCULATE(MIN(quote_history[STAGE DURATION (MINUTES)]),FILTER(quote_history,quote_history[STAGE]="1) Quote Request"&&quote_history[QUOTE ID]=EARLIER(Quote[QUOTE ID])))
=CALCULATE(MIN(quote_history[STAGE DURATION (MINUTES)]),FILTER(quote_history,quote_history[STAGE]="2) Shipping Estimate"&&quote_history[QUOTE ID]=EARLIER(Quote[QUOTE ID])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Asish,
Thank you SO much for your help!
Any idea why it is returning all blanks though? FYI I have just realised my two quote ID fields are called two different things in the schema but they’re related as primary key so that shouldn’t matter should it?

Hi,

As you can see fromy screenshot, the calculated column formula is working very well.  I cannot say why it is not working for you.  Correct for spelling mistakes, if any.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Gingerjeans88 

 

Please use the measure below:

Stage 1 = CALCULATE(MIN('Quote History'[STAGE DURATION (MINUTES)]),FILTER('Quote History',[STAGE]="1) Quote Request"),VALUES('Quote History'[QUOTE ID]))
Stage 2 = CALCULATE(MIN('Quote History'[STAGE DURATION (MINUTES)]),FILTER('Quote History',[STAGE]="2) Shipping Estimate"),VALUES('Quote History'[QUOTE ID]))

 6.PNG

 

Pbix attached,

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
parry2k
Super User
Super User

@Gingerjeans88 in matrix visual

 

QuoteId -> on row from Quote Table

Stage -> On column

Stage Duration (minutes) -> On value

 

and you will get what you are looking for



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you so much for the qukck reply @parry2k !

 

However, my eventual visual is to display something else, this is just a stepping stone. I will then calculate the total minutes per quote and count how many of them met the service level agreement minutes threshold of 1020. 

 

For my original query, I was wanting to create calculated columns to show the stage duration minutes, are you able to help with this?

@Gingerjeans88 well what you explained in original post, I posted teh solution for that, if you provide further details and expected output, we will work on that. 🙂

 

SHare sample data with expected output, it will help to get the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Sorry @parry2k my fault, I am not explaining myself very well! 

 

I have two tables, and in the smaller 'Quote' table I want a new column that contains a value I have looked up from the other (related) table. The Quote table has distinct values and the Quote History has duplicates, hence wanting to return the value within a new column in the Quote (distinct) table. 

 

So the curent tables are as below:

Quote

QUOTE IDCUSTOMER 
Q123Test Customer
Q456Example Client

 

Quote History

QUOTE IDSTAGESTAGE DURATION (MINUTES)
Q1231) Quote Request5
Q1232) Shipping Estimate7
Q4561) Quote Request1
Q4562) Shipping Estimate13

 

And my expected result is as below

 

QUOTE IDSTAGE 1 DURATIONSTAGE 2 DURATION
Q12357
Q456113

 

I want to lookup and return, in the Quote table, the Stage Duration for the Quotes in each stage, ie. achieve the below. Essentially, 'where stage =  1) quote request, display the value in stage duration for that quote id).

@Gingerjeans88 I'm not sure how it is different that original post, with origina reply, just filter  for stage 1 and it will work. I guess when you say stage 1 you mean 1) Quote Request



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I do, yes, 1) Quote Request.

 

I just don't know what DAX to write for the calculated column? Do you mean physically filter or use filter in the DAX? 

 

Sorry for all the questions!

@Gingerjeans88 you can surely add filter on visual level or page level, depending on your needs, just drop Stage column there and filter for "Stage 1" but if you want in measure, add following measure

 

use below measure on value section of matrix and that will do it.

 

Stage 1 Minutes = 
CALCULATE ( SUM ( QuoteHistory[Stage Minutes] ), QuoteHistory[Stage] = "1) Quote Request" )

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks again. Just to clarify though, I am wanting to know how to generate a calculated column in my data model and what DAX to add (filter related? lookup value?) to return the Stage 1 Duration value for each QuoteID in my Quote table, where the 'Stage' in Quote History table = Stage 1 (Quote Request)....not add a matrix visual. As I will need to use the column for further visuals.

Sorry if I am being dumb. 

@Gingerjeans88 the measure calculation I gave , it will work any visual. Matrix visual was just an example. Try that calculation wherever you want to use it and then tell what is not working. I want you to try what you have before asking further question and explain what is not working. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi there,

 

Tried this as dax for my calculated column and it returned all blanks. I know each of the rows in the related table have values in the Stage Duration column. 

 

Thanks

@Gingerjeans88 add it is a MEASURE



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I am so confused, sorry! 

I know you are saying to add it as a measure, but I want a simple row-by-row calculation (lookup, in this case), not an aggregation like what a measure would achieve. 

 

I literally want to find the stage 1 duration, for a quote ID, from the quote history table, and populate it in the new stage 1 duration column in the quote table. 

 

Sorry to keep repeating myself, not trying to be difficult. 

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