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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
BijuDev
New Member

How to use "if" & lookup function together in a condition in power query/ power bi

Hello Team

Need support on how to use IF and Vlookup functions  together in power query or power BI. Example I have two data set like below.
I need to first look for column A, if column is not blank, vlookup the value in  second Data Set 2, retun the Division , else (if A column is blank) lookup the value in colum B ( ie PC column) , return the Division from Data Set 2 ( colum B )

DataSet 1

CCPCAmt
CC5900 10
 PC690245
CC5901 60
   

 

Data Set 2 ( Master)

CC/PCDivision
CC5900Sales
CC5901Marketing
PC6901Sales
PC6902Marketing

 

Output

CCPCAmtDivision
CC5900 10Sales
 PC690245Marketing
CC5901 60Sales
    
1 ACCEPTED SOLUTION
StrategicSavvy
Resolver II
Resolver II

hi @BijuDev ,

 

you can also consider using power query to do this. Here are the steps:

1. go to your Data Set 1 and make sure you have nulls in both column CC / PC

you can use replace values to null them

StrategicSavvy_0-1710081370796.png

 

2. add new column in your dataset 1 using double question marks (coalesce operator)

StrategicSavvy_1-1710081439397.png

you will get this column :

StrategicSavvy_2-1710081469197.png

3. merge your dataset 1 with dataset 2

 

StrategicSavvy_3-1710081508685.png

 

4. expand your table and select division column 

StrategicSavvy_4-1710081547439.png

 

 

 

PBIX 

 

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: www.linkedin.com/in/lukasz-kozdron 

 

View solution in original post

4 REPLIES 4
BijuDev
New Member

Thanks Luca, I created a calculated column on Data Set 1 using above method. However,  I need one more column in Data Set 1 which should retun corresponding Divison Name from Data set 2 ( look up array)

You have to connect the two table and create the measure to do the calculation.



Luca D'Elicio

LinkedIn Profile
StrategicSavvy
Resolver II
Resolver II

hi @BijuDev ,

 

you can also consider using power query to do this. Here are the steps:

1. go to your Data Set 1 and make sure you have nulls in both column CC / PC

you can use replace values to null them

StrategicSavvy_0-1710081370796.png

 

2. add new column in your dataset 1 using double question marks (coalesce operator)

StrategicSavvy_1-1710081439397.png

you will get this column :

StrategicSavvy_2-1710081469197.png

3. merge your dataset 1 with dataset 2

 

StrategicSavvy_3-1710081508685.png

 

4. expand your table and select division column 

StrategicSavvy_4-1710081547439.png

 

 

 

PBIX 

 

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: www.linkedin.com/in/lukasz-kozdron 

 

lucadelicio
Super User
Super User

Hi,
try to craete the same CC/PC Column also in the dataset 1.
Add calculated column:
CCPC =
IF(ISBLANK(CC), PC, CC)
Then you can connect the dataset1 with dataset2 on CC/PC Column and do the calculation with the measure that you want.
Mark as a solution my answer if i help you.
Thank you.



Luca D'Elicio

LinkedIn Profile

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.