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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Fetch Value of a column from 2nd table depending on condition from 1st table

Hi All,

 

I want to fetch the value of Date from TAB2 depending on the *Condition(listed below) from the TAB1.

TAB1   
Company Key fieldInvoice numberDoc number
ABCX15123456123456
ABCX11234561245987

 

TAB2  
Company Invoice numberDate
ABCX12345601-01-2000 10:00
ABCX12345602-01-2000 10:00

 

The condition is fetch the value of the date field from TAB2 for the same invoice number present in TAB1 only if the Key field value is "15" for the same invoice number in TAB1

 

This is what i have written but it says memory error. Any idea where I am going wrong?

Pay Date = if('TAB1'[Invoice Number] == 'TAB1'[Doc Number],if('TAB1'[key field] = "15",LOOKUPVALUE('TAB2'[Date],'TAB2'[Invoice Number],'TAB1'[Doc Number])))

 

I have created a new column and have applied the query to the same column

 

Thanks in Advance.

@amitchandak 

12 REPLIES 12
v-yetao1-msft
Community Support
Community Support

Hi @Anonymous 

If possible, please provide your pbix file(remove sensitive info) so that we can create the results you need based on your model .

 

Best Regards,
Community Support Team _ Ailsa Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Samarth_18
Community Champion
Community Champion

Hi @Anonymous ,

 

You could try to create a column as below:-

Pay Date = 
IF (
    'Tab1'[Invoice Number] = 'Tab1'[Doc Number]
        && 'Tab1'[key field] = 15,
    CALCULATE (
        MAX ( 'Tab2'[Date] ),
        FILTER ( Tab2, 'TAB2'[Invoice Number] = 'Tab1'[Doc number] )
    )
)

 

Samarth_18_0-1660992701197.png

 

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Anonymous
Not applicable

Hi Samarth,

 

I tried but I am getting Out of Memory error 

tamerj1
Super User
Super User

Hi @Anonymous 

Is there any relationship between the two tables? Can you create/modify relationships? Which of the dates would like to retrieve? For example the first date or the last date?

Anonymous
Not applicable

Yes there is relationship maintained between the tables.

I typed the second date accidentally, I just want the date value from tab 2 with the conditions mentioned above. 

@Anonymous 
Which columns are involved in the relationship?

Anonymous
Not applicable

poojakarekar1_0-1660992236980.png

I am getting this error even if i try doing it for just one entry 

Anonymous
Not applicable

Hi,

Try something like this:

Date tab2 = IF('Table (8)'[Key field]="15",CALCULATE(MAX('Table (9)'[Date]),'Table (9)'[Invoice number]=EARLIER('Table (8)'[Invoice number])),BLANK())

ValtteriN_0-1660991494040.png



I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

I tried the solution, but I am getting memory error.

In that case the problem is with your model optimization. Try creating a measure. E.g.

Date tab2_m = IF(max('Table (8)'[Key field])="15",CALCULATE(MAX('Table (9)'[Date]),'Table (9)'[Invoice number]=max('Table (8)'[Invoice number])),BLANK())

ValtteriN_0-1660992447620.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi, 

 

I am getting an error "unexpected parameter BLANK() when I type the measure. I have used the same code that you have provided

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.