SOLVED

Need help to build excel logic

Brass Contributor

Hi everyone,

just need some help on building logic in excel where it checks for following conditions and returns the output:

In the image as shown below, I want a logic in cell A2, which will check for conditions in cell B, C, D. 

  1. if I have UCN 1256 in cell B2, facility in C2 as Unity, and Facility short as UN in cell D2, I want the formula in cell A2 to return 1256-Unity
  2. If I have UCN 1256 in cell B2, facility in C2 as "blank", and Facility short as UN in cell D2, I want the formula in cell A2 to return 1256-UN
  3. if I have UCN 1256 in cell B2, facility in C2 as Unity ,and Facility short as "blank" in cell D2, I want the formula in cell A2 to return 1256-Unity

AKuma0411_1-1705442716476.png

 

By default, it should always pull UCN and long name, but in cases where we don't have the long name it should return UCN and short name. Also, when B,C,D are all blank it should just have "-" in cell A2. 

This is the logic I tried so far-

=IF(AND(B2<>" ",C2<>" ",D2<>" "), B2 &"-"& C2,IF(C2<>" ", B2 &"-"&D2," "))

It seems to be working fine for first and third conditions but it's not working as expected for 2nd condition. pls see the image for reference

 

AKuma0411_0-1705440108380.png

2 Replies
best response confirmed by AKuma0411 (Brass Contributor)
Solution

@AKuma0411 

Try this:

=TEXTJOIN("-",FALSE,B2,IF(C2="",D2,C2))
thank you so much! this is perfectly doing the job
1 best response

Accepted Solutions
best response confirmed by AKuma0411 (Brass Contributor)
Solution

@AKuma0411 

Try this:

=TEXTJOIN("-",FALSE,B2,IF(C2="",D2,C2))

View solution in original post