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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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