+ Reply to Thread
Results 1 to 8 of 8

constructing IF logical test based on text string stored in other cell

Hybrid View

  1. #1
    Registered User
    Join Date
    02-10-2014
    Location
    Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    5

    constructing IF logical test based on text string stored in other cell

    Hello! I know how to use text stored in quotes with an IF function to perform a logical test, such as =IF(A1="red",result if true, result if false). Is there a way to base the logical test on a text string stored in a different cell?

    Sheet1 contains a large dataset. Each row contains a numerical score (0-100) in column A, one of 50 U.S. state abbreviations in column B (eg, IL, MS, WA), and several other criteria used in other parts of the spreadsheet. On the summary tab, I need to do some calculations (like median and standard deviation) on the scores on sheet1 based on text in several of the other columns, such as col A (state). Since MEDIAN and STDEV functions don't have "ifs" variants (like SUMIFS and AVERAGEIFS), I need to use IF statements to make the calculations work.

    I want to construct one IF statement where the logical test is based on a text string contained in a cell from the same row so that when I pull down the formula to fill in, the rows below the first formula calculate based on the corresponding text (state abbreviation) in that row.

    Thanks in advance for your input!

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: constructing IF logical test based on text string stored in other cell

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    Without an example, the best I can offer is that it's absolutely possible to change the word "red" to a cell reference, such as A1, or to insert a LOOKUP or any other number of expressions.

    Almost all functions allow for the substitution of their arguments with further nested formulas.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    02-10-2014
    Location
    Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: constructing IF logical test based on text string stored in other cell

    Hi daffodil11,

    I'd rather not upload a sample workbook, but here are two tables showing the data and summary sheets as examples:

    Data tab

    A B C D
    1 State Score County Date
    2 MD 89 Ionia 9/6/2012
    3 MD 81 Monroe 8/28/2012
    4 AK 93 Washtenaw 8/27/2012
    5 AK 91 Arenac 8/27/2012
    6 AK 77 Madison 7/6/2012
    7 ND 82 Madison 7/3/2012
    8 TX 93 Jackson 7/5/2012
    9 MD 77 Isabella 6/19/2012
    10 VA 89 Tuscola 8/14/2012

    Summary tab

    A B
    1 State Standard Deviation
    2 AK #DIV/0! <-the formula in B2 is {=STDEV(IF(Data!B2:B10=Summary!B2,Data!C2:C10))} (Even confirmed with ctrl-shift-enter, the result is an error)
    3 AL
    4 AR
    5 AS
    6 AZ
    7 CA
    8 CO
    9 CT
    10 DC

    I am trying to construct a formula in B2 that can be pulled down. In B3, I want to see the standard deviation for all scores in Alabama. In B4, the standard deviation for Arkansas, etc. This is a much larger dataset, and there are criteria other than states I want to use elsewhere. So for now I'm just trying to understand the concept of basing the logical test on a text string in a different column. Just naming the cell containing the text string (e.g. A2 or even &A2) doesn't seem to work with IF functions unless I'm missing some crucial syntax. Thanks so much again!

  4. #4
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: constructing IF logical test based on text string stored in other cell

    STDEVIF:
    =SQRT((SUMPRODUCT(val_range, val_range, --(test_range=test)) -2* AVERAGEIF(test_range, test, val_range) *SUMIF(test_range, test, val_range)) / COUNTIF(test_range, test) +AVERAGEIF(test_range, test, val_range)^2)
    somebody check my math on that please? I might have screwed up the algebra.

    MEDIANIF, just using an array formula:
    {=MEDIAN(IF(test_range = test, val_range))}
    Last edited by ben_hensel; 09-26-2014 at 03:33 PM.

  5. #5
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: constructing IF logical test based on text string stored in other cell

    You can use a CHOOSE function with a nested vlookup array for this.

    If I understand correctly, you want to drag a single formula down, but have the formula use different functions based on the data on the row. To oversimplify it, row 1 you might want to do a =SUM(A1:F1) but on row B you need to =SUMIF(A1:F1,A1)

    The Concept:

    Create a with the different possible functions, and an index number associated with that function. Just basic 1,2,3,4,5.

    So
    SUM 1
    RANK 2
    PRODUCT 3

    Now you use a VLOOKUP to grab that index number

    =VLOOKUP(F1,the_above_table,2,0)

    Now, make a CHOOSE function, and list all the formulas inside it using the VLOOKUP above as the index

    =CHOOSE(VLOOKUP(F1,the_above_table,2,0),SUM(A1:F1),RANK(A1:F1,C1,D1),PRODUCT(A1,B1,D1))



    If I didn't understand the question correctly, then this is all pretty useless to you and I have wasted 12 minutes.



    Note: If you can't make a table for the vlookup, make an array in the formula

    =VLOOKUP(A1,{"SUM",1;"RANK",2;"PRODUCT",3},2,0) will do the exact same thing
    Last edited by Speshul; 09-26-2014 at 03:28 PM.
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: constructing IF logical test based on text string stored in other cell

    Worked fine for me. I had to adjust the target ranges slightly.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    02-10-2014
    Location
    Minnesota
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: constructing IF logical test based on text string stored in other cell

    It certainly does work. I don't see what was causing the error when I attempted your solution earlier using a named range for the column containing the scores instead of the cell reference itself. But the IF statement seems to work fine now based on text contained in another cell.

    By the way, sorry for perhaps including too much context in my original post. I fear it may have made the problem I was looking to solve appear broader than it was.

    Thanks so much to all!

  8. #8
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: constructing IF logical test based on text string stored in other cell

    That's fine, we're used to it. It's interesting to see the logical applications though.

    For me, solving a lot of posts are about translating specific issues into general terms.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] convert value stored as text to logical refrence value!
    By Don Guillett in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 11:05 AM
  2. [SOLVED] convert value stored as text to logical refrence value!
    By Remote Desktop Connection hotkey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  3. [SOLVED] convert value stored as text to logical refrence value!
    By Don Guillett in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 07:05 AM
  4. convert value stored as text to logical refrence value!
    By Remote Desktop Connection hotkey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 01:05 AM
  5. change text color based on logical test
    By T3nMan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-19-2005, 01:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1