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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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

https://www.linkedin.com/in/luca-d-elicio-74a481158/
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

https://www.linkedin.com/in/luca-d-elicio-74a481158/

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Kudoed Authors