SOLVED

# Need help to build excel logic

Brass Contributor

# Need help to build excel logic

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

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

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

# Re: Need help to build excel logic

Try this:

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

# Re: Need help to build excel logic

thank you so much! this is perfectly doing the job
1 best response

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

# Re: Need help to build excel logic

Try this:

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