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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
obriaincian
Resolver I
Resolver I

Lookup to see if a column contains a specific value, if true then

Hi All,

 

I'm stuck on this one,

 

I've 2 tables

 

DF1

ID
11
22
33
44
55

 

 

DF2

IDTaskDate 1 Date 2
11Act 1 12/02/2022
11Act 215/05/202225/05/2022
22Act 105/06/202201/08/2022
22Act 204/02/202213/02/2022
33Act 11/11/2022 
33Act 219/12/202324/05/2022
44Act 218/03/202602/02/2022
44Act 212/08/202317/05/2022
55Act 122/05/202409/09/2020

 

I need to add a column to DF1, the logic for this column is as follows:

Scenario 1 - Where the ID has the Task "ACT 1" use Date 1, If Date 1 is empty Use Date 2.

Scenario 2 - Where the ID has no Task "ACT 1" use Date 2.

 

Apologies for the table formatting

 

Thanks,

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @obriaincian ,

 

Approve with @ryan_mayu .

Since you didn't give the logic for calculating Date2 such as ID 44, I'll tentatively return it as blank(If this is not your logic, please provide more details). Dax is as follows:

 

Column = 
var _a = SELECTCOLUMNS(FILTER('DF2',[ID]=EARLIER(DF1[ID])),"Task",[Task])
var _b = MAXX(FILTER('DF2',[ID]=EARLIER(DF1[ID])&&[Task]="Act 1"),[Date 1])
var _c = MAXX(FILTER('DF2',[ID]=EARLIER(DF1[ID])&&[Task]="Act 1"),[ Date 2])
return IF("Act 1" in _a &&_b<> BLANK(),_b,_c)

 

Final output:

vjianbolimsft_1-1668136755234.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

Hi @obriaincian ,

 

Approve with @ryan_mayu .

Since you didn't give the logic for calculating Date2 such as ID 44, I'll tentatively return it as blank(If this is not your logic, please provide more details). Dax is as follows:

 

Column = 
var _a = SELECTCOLUMNS(FILTER('DF2',[ID]=EARLIER(DF1[ID])),"Task",[Task])
var _b = MAXX(FILTER('DF2',[ID]=EARLIER(DF1[ID])&&[Task]="Act 1"),[Date 1])
var _c = MAXX(FILTER('DF2',[ID]=EARLIER(DF1[ID])&&[Task]="Act 1"),[ Date 2])
return IF("Act 1" in _a &&_b<> BLANK(),_b,_c)

 

Final output:

vjianbolimsft_1-1668136755234.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jianboli-msft Yes ID 44 should be blank as there is no ACT 1, thank you

ryan_mayu
Super User
Super User

@obriaincian 

Let's see ID 44, don't have ACT 1 and has two date 2, then what date will you use?





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

Proud to be a Super User!




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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.