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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Comparing a value with a range in related table when another column matches

Hello Gurus,

I have a situation as following:

I have two table as the screenshots you see here:

Dic.jpg

2019-06-30_11-32-44.jpg

 

My final goal is to create a Custom Column in which it produces the values in Col F of the first table (1st screenshot), it has 7 values like F1, F2, F3, F7 and it's Text type, when the values in column Max of the second table(below screenshot) falls between the Min and Max of the first table.

So to sum up, I have made a connection through Column Key in both tables. I have 2 different conditions:

1. Check if Column Code of 2nd table matches with Column Code of first table (as relevant screenshots)

2. Check if the value in Column Max of the second table falls between the Min and Max columns of the first table 

then it shows the relevant value in Column F of the first table(1st screenshot) in the custom column of the 2nd table. Just an extra note, finally I have Sum the values in final Qty based on their value in column F of the 2nd table to show in my visual.

 

 

Many thanks in advance.

P.s. values in col Final Qty, Min, Max and Max of both tables are Type Whole Number  and everything else is Type text.

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Believe that the best option is to use the FIRSTNONBLANK formula applying a FILTER to the columns you need.

 

Add a custom column with the following code and see if it works.

 

 

F Code =
CALCULATE (
    FIRSTNONBLANK ( Table1[F]; 1 );
    FILTER (
        Table1;
        Table1[Code] = Table2[Code]
            && Table1[Max] >= Table2[Max]
            && Table1[Min] <= Table2[Max]
    )
)

 

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

8 REPLIES 8
RobbeVL
Impactful Individual
Impactful Individual

Hi,

 

You will need to merge the columns and create a custom column with an IF statement.
Create a sample pbix file, and I'd be happy to help further.

Robbe

Anonymous
Not applicable

@RobbeVL,

No need to leave a general comment please!

Already tagged my question with IF and mentioned custom column in its body,

Thanks

RobbeVL
Impactful Individual
Impactful Individual

My main point was,
Create a sample pbix file...
Dont always expect minimum effort for maxiumum result...

Hi @Anonymous ,

 

Believe that the best option is to use the FIRSTNONBLANK formula applying a FILTER to the columns you need.

 

Add a custom column with the following code and see if it works.

 

 

F Code =
CALCULATE (
    FIRSTNONBLANK ( Table1[F]; 1 );
    FILTER (
        Table1;
        Table1[Code] = Table2[Code]
            && Table1[Max] >= Table2[Max]
            && Table1[Min] <= Table2[Max]
    )
)

 

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@MFelixThanks!

The only part is that I have vriable Max values which makes it difficult to group and generalize them using the FirstBlank!

This is why I am confused

 

Hi @Anonymous,

Not understanding your issue, what do you mean you have a varia ble max value?

I have tested out with several values and several levels of Max and min and the result was matchig.

Regards,
MFelix

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Thanks @MFelix  for taking the time to reply. Actually in the pic I shared the value in the Max column varies based on the value in column F and Column Code. Maybe the best question I should have asked you was what Firstnonblank() function does in the measure? If you please explain it a little bit more I think it might be the most helpful hint

Thank you very much again @MFelix  and looking forward to hearing from you

Hi @Anonymous,

Since the values you have on the lookpvalue has to compare values from 2 different columns and tables this is not possible using the LOOKUPVALUE function.

The FIRSTNONBLANK returns the first value on the table that is not blank when you add tje filter with your options it finds the first value that matches your criteria, so in this case you can only have an incorrect result if the ID, Min and Max column on the table you are making the search as the same values for the 3 columns.

Regards,
MFelix

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.