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
johnyip
Super User
Super User

How to look up values based on boolean logic

Sample data

 

Table A

Shop

Value

From_year

To_year

A

12

2019

2021

A

345

2022

2023

 

Table B

Shop

Year

A

2020

A

2023

 

I want to create a calculated column [Value_looked_up] in Table B, with the expected result as below:

 

Table B

Shop

Year

Value_looked_up

A

2020

12

A

2023

345

 

The result is to perform lookup with [shop], returning the relevant [value] when 'Table B'[Year] >= 'Table A'[From_year] and Table B'[Year] <= 'Table A'[To_year].

 

Any ideas how to do that? I tried LOOKUPVALUE(), but this function seems won't allow boolean logic in its syntax.

Much appreciated for the help.



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!
2 ACCEPTED SOLUTIONS
Ahmedx
Super User
Super User

Thanks for the help, your answer has reminded me of how powerful CALCULATE() is supposed to be.

Was looking into LOOKUPVALUE() while forgetting this can be done by CALCULATE().

 

And my since my actual data is not numeric, for those who wish to lookup text, please try the following:

 

Value = CALCULATE(MAX('Tab_A'[Value]),
                  FILTER('Tab_A',[To year]>=[Year] && [From year]<=[Year])
        )

 

 



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!

View solution in original post

2 REPLIES 2
Ahmedx
Super User
Super User

Thanks for the help, your answer has reminded me of how powerful CALCULATE() is supposed to be.

Was looking into LOOKUPVALUE() while forgetting this can be done by CALCULATE().

 

And my since my actual data is not numeric, for those who wish to lookup text, please try the following:

 

Value = CALCULATE(MAX('Tab_A'[Value]),
                  FILTER('Tab_A',[To year]>=[Year] && [From year]<=[Year])
        )

 

 



Please mark my post as the solution if this answers your question!
Appreciate your Kudos !!

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.