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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Lookup with if Condition

Hello,

Can anyone have advice for below?

I am trying to do lookup with if condition and below is my calculated column and I am getting below error

 

“Function LOOKUPVALUE expects a column reference as argument number 4.”

 

calcualte Column in  MAIN TABLE = IF(LOOKUPVALUE(Sheet2[Avg],Sheet2[Product Name],[Product],Sheet2[Product Name]<>BLANK(),"Empty"

 

Main Table

 

Lookup Table

Product

Avg

 

Product Name

Avg

A

 

 

A

100

B

 

 

B

200

C

 

 

D

300

E

 

 

E

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@Anonymous

 

A zero. Simply the number: 0.

 

NewAvgColumn =
VAR _LookedUpAvg =
    LOOKUPVALUE ( Sheet2[Avg], Sheet2[Product Name], MainTable[Product] )
RETURN
    IF ( NOT ISBLANK ( _LookedUpAvg ), _LookedUpAvg, 0 )

But I'm not sure that's the best option because, how will you tell if the average was actually a zero or the name wasn't present in the other table? I would stick with the blank as we had in the first version    

View solution in original post

13 REPLIES 13
Greg_Deckler
Community Champion
Community Champion

I would create a VAR that is your Sheet2 table filtered by [Product Name] <> BLANK() and then filter down from there. So, something like:

 

Column = 

VAR __table = FILTER(ALL('Sheet2'),[Product Name] = [Product] && [Product Name] <> BLANK())

RETURN

...

 

I'm not understanding your data though. 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



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...
AlB
Community Champion
Community Champion

Hi @Anonymous

 

Following what the error message says, look at the "argument 4"  of your lookupvalue:

Sheet2[Product Name]<>BLANK()

I guess you forgot to close the parenthesis for lookupvalue right before that. In any case if you explain exactly what the code needs to do I'd be able to help with the solution. I'm not sure what's required right now. 

Anonymous
Not applicable

Hi AIB,

what i am trying to do in lookup table if column Product name is blank then display message "No".

 

Requirements:

Maine table and Lookup table does not have any relationship.I want Avg from lookup table Avg , if Lookup Table Product name is empty or null then message should say "No".

let me knof if you need more inforamation.

Thanks

 

 

AlB
Community Champion
Community Champion

Hi @Anonymous

 

If I understand correctly what you need, try this:

 

NewAvgColumn =
VAR _LookedUpAvg =
    LOOKUPVALUE ( Sheet2[Avg], Sheet2[Product Name], MainTable[Product] )
RETURN
    IF ( NOT ISBLANK ( _LookedUpAvg ), _LookedUpAvg )


  This will leave blank wherever the name is not found in table2. Note that it is not allowed to have different data types in the same column so the result when not found cannot be text as you were asking for, since the rest is numbers. You could either return a blank as the code does or another number (outside the range of possible results for Avg) that you know means "Not found"

It is a best practice to use a fully qualified name for columns, i.e. including column name: TableName[ColumName] so that a column can be readily differentiated from a measure, which will not use the table name: [MeasureName]

Anonymous
Not applicable

Hi AIB,

Please see below final result should look like,

Final Result
ProductAvg
A100
B200
C"N/A" or 0000
E"N/A" or 0000
AlB
Community Champion
Community Champion

@Anonymous

Like I said in my previous post, you can't. A column can only have one data type so if you want to show a zero it will have to be a "normal" one. 

Anonymous
Not applicable

Hi AIB,

I have tried to put IF(NOT ISBLANK(00000),_LOOKEDUPAVG) and i am not able to see 00000.Not sure about "Normal".Please explain

    IF ( NOT ISBLANK ( _LookedUpAvg ), _LookedUpAvg )

 

AlB
Community Champion
Community Champion

@Anonymous

 

A zero. Simply the number: 0.

 

NewAvgColumn =
VAR _LookedUpAvg =
    LOOKUPVALUE ( Sheet2[Avg], Sheet2[Product Name], MainTable[Product] )
RETURN
    IF ( NOT ISBLANK ( _LookedUpAvg ), _LookedUpAvg, 0 )

But I'm not sure that's the best option because, how will you tell if the average was actually a zero or the name wasn't present in the other table? I would stick with the blank as we had in the first version    

Anonymous
Not applicable

Hi AIB,

Thank you so much for your help.

<AIB>But I'm not sure that's the best option because, how will you tell if the average was actually a zero or the name wasn't present in the other table? I would stick with the blank as we had in the first version 

 

I have used 00000 and it is my indicator to use in with other calculated column and when end user see 00000 they understand there has no AVG available for the product.

AlB
Community Champion
Community Champion

@Anonymous

How have you used 00000?

 

Anonymous
Not applicable

Hi AIB,

calculated column=if (column =00000,"y","n").Once i get "y" and "n" i am will use this for next calculation.

let me know if you need more inforamation.

thanks

 

AlB
Community Champion
Community Champion

@Anonymous

Ok, but 00000 as a number is still  and exactly the same as 0. It will be shown as 0, your users will see 0, not 00000

If you did the following, you will have simple zeros in your column. Don't you?

 

NewAvgColumn =
VAR _LookedUpAvg =
    LOOKUPVALUE ( Sheet2[Avg], Sheet2[Product Name], MainTable[Product] )
RETURN
    IF ( NOT ISBLANK ( _LookedUpAvg ), _LookedUpAvg, 00000 )

 

Anonymous
Not applicable

Hi AIB,

It works perfectly fine but how can i display "N/a" or 0000 when when name not found in table 2.

 

<AIB>This will leave blank wherever the name is not found in table2.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors