WISDOMBYDATA
  • BLOG
    • Blog Guide
    • Blog History
  • EXCEL
    • Functions & Formulas
    • VBA & Macros
    • VLOOKUP
    • Pivot Tables
    • Conditional Formatting
    • Tricks & Shortcuts
  • BI
    • SAP BOBJ/BW
    • Tableau
  • SQL
  • ABOUT
    • About WBD
    • About Me

Using the ISTEXT Function of Excel in String Concatenations

8/22/2014

0 Comments

 
In MS Excel the ISTEXT function can be used to check for a text value in a cell. When applied to a single cell this function will return “True” or “False” based on whether or not there is a value (any value) in the desired cell.
Example: the formula below will return “True” if there is any value in cell A1, otherwise “False” will be returned.

=ISTEXT (A1)  


Very recently I came across a situation where using the ISTEXT function within a formula allowed me to perform a given task efficiently and with much higher precision. Consider the table below as an example:
Picture
The task I want to perform here is to concatenate the values in each row into a single cell. In other words, I want to take the values is cells A, B, C, D, and E for each given row and concatenate them into one single cell. I am also required to have a underscore (_) between the joining cells (i.e. Cells A through E).  Doing so is rather simple. All I have to do is to insert the formula below in a cell (cell G2 in this case) and apply the formula to the full range by dragging it down.:

=A2&"_"&B2&"_"&C2&"_"&D2&"_"&E2

NOTE] The following formula could also be used as an equivalent substitute for the formula above

=CONCATENATE(A2,"_",B2,"_",C2,"_",D2,"_",E2)


Here is the outcome after applying either one of these two formulas:
Picture
While it may seem that the formula above has delivered the desired results, there is one flaw that this formula could not address: extra Underscores!. To get a better idea have a look at the values for fields C through E. Not all the cells in this range have a value and the blank cells (located in columns D and E) are detrimental as they result in additional and unwanted underscores at the end of the string concatenation (see cells G3, G6, G7, G9, and G11).
Picture
The traditional way to suppress these unwanted underscores is by manually altering the formula for those rows that contain blank values. Doing so may be rather simple in the example that I provided, however; imagine if we were dealing with hundreds, thousands or even more records. In such situations altering select formulas would become rather time consuming and daunting.

By utilizing the “ISTEXT” function we could arrive at the desired results with no additional underscores without needing to alter formulas for select cells. Here is how to do this:
 
I will insert the formula below, which contains embedded ISTEXT statements, in cell G2 and then I will drag it down to cover the entire range:

=A2&"_"&B2&"_"&C2&IF(ISTEXT(D2),"_"&D2,"")&IF(ISTEXT(E2),"_"&E2,"")


 Here is the end result:
Picture
As could be observed, using this formula has suppressed all unwanted underscores and most importantly eliminated the need for manually customizing the formulas for those rows that have blank cells. AMAZING!

0 Comments
<<Previous

    Categories

    All
    BI
    EXCEL
    MISC
    SQL

    Archives

    June 2020
    May 2020
    April 2020
    March 2020
    February 2020
    December 2019
    November 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    September 2017
    August 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    May 2015
    April 2015
    March 2015
    February 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013

Powered by Create your own unique website with customizable templates.
  • BLOG
    • Blog Guide
    • Blog History
  • EXCEL
    • Functions & Formulas
    • VBA & Macros
    • VLOOKUP
    • Pivot Tables
    • Conditional Formatting
    • Tricks & Shortcuts
  • BI
    • SAP BOBJ/BW
    • Tableau
  • SQL
  • ABOUT
    • About WBD
    • About Me