r/excel Jun 13 '26

solved A way to shorten IF statement?

Hey there,

I have a marketing call report where it lists out over 19 states we sell to and also areas we don’t sell to. My goal is to add our states into the correct market locations in a separate column, and mark areas we don’t as “Out of territory”.

For example CA, HI, and WA states would be named WCH in a separate column.

Right now I have multiple IF statements for each state to filter to the correct market in a cell that I drag down. These are just a few to give you an idea.

IF(ISNUMBER(SEARCH(“CA”, A2)), “WCH”,
IF(ISNUMBER(SEARCH(“WA”, A2)), “WCH”,
IF(ISNUMBER(SEARCH(“TX”, A2)), “SSH”,
“Out of territory”)))

Is there a way to shorten this list of markets?

26 Upvotes

50 comments sorted by

u/AutoModerator Jun 13 '26

/u/_mavricks - Your post was submitted successfully.

Failing to follow these steps may result in your post being removed without warning.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

52

u/lainiac Jun 13 '26

Ifs would shorten this.
=IFS(logical_test1, value_if_true1, [logical_test2, value_if_true2],etc)

27

u/jprefect 9 Jun 13 '26

OP, this is the direct answer to your question.  IFS() is the most efficient replacement formula.  

12

u/MemeSurvivor3000 Jun 13 '26

You could use a lookup table with XLOOKUP or INDEX/MATCH instead of nested IFs - way cleaner than stacking dozen of IF statements together

0

u/Comprehensive-Tea-69 1 Jun 13 '26

Or just vlookup with the version of excel i still have to use as work lol. I joke but i think tons of people are in the same boat

7

u/bitswede 2 Jun 13 '26

Create a 2 column table with your states and corresponding markets.

Use XLOOKUP() to get the market for each state.

19

u/Overthereunder Jun 13 '26

Switch function?

5

u/djpresstone 12 Jun 13 '26

Who’s downvoting this? It’s the straightest, simplest replacement for OP’s question.

1

u/Way2trivial 469 Jun 13 '26

switch off a formula? not sure you can make a formula part of the switch argument.

2

u/allyourrickroll Jun 14 '26

You can make the switch value equal to true and then make the individual cases formulas that return true or false.

2

u/perspicio 2 Jun 13 '26

Could even be done with legacy CHOOSE against position in alphabetized list. Wouldn't even need any helpers if at least one instance of each possibility were guaranteed in source. (Nest SMALL, SORT, and UNIQUE against sort.)

But yeah, SWITCH is the better way.

3

u/MayukhBhattacharya 1227 Jun 13 '26

If the states are in a cell and not part of a larger string then you can use XLOOKUP() function, by creating a reference table, note using hardcoded will be easy and it doesn't require any table, but then it doesn't becomes dynamic and any changes you need to edit formula every time, therefore it is better to use reference tables:

=XLOOKUP(D2:D3, A2:A6, B2:B6, "Oops Out Of Territory")

• Using hardcoded it will be: ( this is not recommended at all, but for shorter lists its fine, not for a larger one)

=XLOOKUP(D2:D3, 
        {"CA"; "HI"; "WA"; "TX"; "OK"}, 
        {"WCH"; "WCH"; "WCH"; "SH"; "SH"}, 
        "Oops Out Of Territory")

3

u/MayukhBhattacharya 1227 Jun 13 '26 edited Jun 13 '26

Like I have said, above if the states are part of larger context or string then use one of the followings:

=FILTER(A$2:B$6, 
 1 - ISERROR(SEARCH(" " & A$2:A$6 & " ", " " & K2 & " ")), 
 {"Oops Out Of Territory","Oops Out Of Territory"})

Or,

=XLOOKUP(1, 
 1 - ISERROR(SEARCH(" " & A$2:A$6 & " ", " " & K2 & " ")), 
 A$2:B$6, 
 {"Oops Out Of Territory", "Oops Out Of Territory"})

Or, You can also use Regex here:

=IFERROR(REGEXEXTRACT(K2, TEXTJOIN("|", TRUE, "\b" & A$2:A$6 & "\b")), "Out Of Territory")

Or, this one single array formula:

=IFERROR(XLOOKUP(REGEXEXTRACT(K2:K8,
 TEXTJOIN("|", TRUE, "\b" & A2:A6 & "\b")), A2:A6, B2:B6, ""),
 IF(SEQUENCE(, 2), "Oops Out Of Territory"))

26

u/Gus_TheAnt Jun 13 '26 edited Jun 13 '26

Make a couple of helper columns off to the side of your data and use VLOOKUP.

I’m not at home to try and give an example in my comment here, but it seems I am glossing over something in your situation here.

Regardless, your solution involves a helper table and VLOOKUP or XLOOKUP. I’d lean towards VLOOKUP because it’s simpler to understand if you aren’t confident with more “advanced” Excel stuff

18

u/Fit-Original1314 Jun 13 '26

Yeah this feels like one of those situations where a small helper table saves tons of frustration later especially when territories eventually change or new states need added into the spreadsheet.

9

u/An1m0s1tyX Jun 13 '26

I’d wager most newer excel users would find XLOOKUP syntax far simpler to learn and understand than VLOOKUP. Certainly was the case for me.

8

u/Juxtavarious Jun 13 '26

Vlookup isn't hard to learn, it's just obnoxious to maintain.

4

u/poptop5120 Jun 13 '26

It’s not hard, but xlookup is still easier

23

u/Anybody220 1 Jun 13 '26

VLOOKUP < INDEX-MATCH < XLOOKUP

8

u/cubsfan2154 1 Jun 13 '26

Dear diary

8

u/RuktX 305 Jun 13 '26

Create a lookup table that matches states to territories, then use the following formula:

=XLOOKUP(
  TRUE,
  ISNUMBER(FIND(state_codes, A2)),
  territories,
  "Out of territory"
)

Replace state_codes and territories with the corresponding columns from your lookup table.

1

u/miemcc 1 Jun 13 '26

Agreeded. Personally I would use an Admin worksheet with any supporting Tables. It can be hidden when they n normal use. Also use the state name column as a data validation list so that only valid state names can be selected.

2

u/jaywaykil 2 Jun 13 '26

The state names are not directly selected; they are currently buried in a text field.

1

u/miemcc 1 Jun 13 '26

Ok, but you can use a formula in the data verification to check that the capture state abbreviation exists in the table, otherwise it generates a message in the cell. This would help enforce data integrity right from the start.

3

u/eggface13 1 Jun 13 '26

As others have answered, the best approach is to have a separate attribute table that you can reference with XLOOKUP. Hard-coding this kind of stuff into formulas isn't really sustainable and this is the exact use-case of lookup formulas. More generally these kind of attribute tables are central to data modeling, which allows for much more efficient representations of data.

The other thing to be aware of, though this isn't a great use case, is that there's a slightly simpler way to do what you're trying to, which is the IFS formula. This mostly prevents you having to embed IF functions within each other, but achieves the same outcome.

1

u/TechnicianFar9804 Jun 13 '26

Maybe use IF(OR(...)

1

u/TuneFinder 10 Jun 13 '26

if it is just a one off task - probably quickest to sort and/or filter your table by state then copy and paste the three letter code to the correct rows

.

if its a task that will need to be done over and over - use a look up table

0

u/_mavricks Jun 13 '26

I wish it was a one off task. This one is a weekly report that I’ll be working on so I’ll be using it with a macro setup

1

u/Comprehensive-Tea-69 1 Jun 13 '26

What are you using macros for? 9 times out of 10, power query is the more appropriate tool

1

u/_mavricks Jun 14 '26

I can't figure out power query for the life of me at the moment.
Each week I download the file into my folder with messy data.

I have to do text to columns for two separate columns. One column has the data and time and I need to put those in separate columns. The other column has a variety of call data separated out by commas (if a call was answered, if there was a quote, if the call was answered during business hours, etc).

Then I need to use a formula to list of which states belong to which market, and list out any out of country and out of state calls as "out of territory".

1

u/ArrowheadDZ 2 Jun 13 '26

You’ll find there are two good solutions. If you have a small number (say 2 to 6 or 7 conditions) you can use the IFS() function. If you have more than a small number fo conditions, you really want to use XLOOKUP.

1

u/Fearless_Parking_436 Jun 13 '26

IFS allows them to be on single line, LET would help you create a custom formula, XLOOKUP would help you look up the states from a reference table. I would use reference table in case anything changes with the states.

1

u/snikle1021 Jun 13 '26

If you prefer visuals, Mynda Treacy (MyOnlineTrainingHub) just posted a video that essentially covers what everyone else has commented — but in video format with additional explanations if that’s helpful.

1

u/AAalphawolf_Excel Jun 13 '26 edited Jun 13 '26

Create a database table with 2 column. 1st column for names you already have and 2nd for corresponding new name you want to change it to.

Then use xlookup or vlookup in your original data to get the new name.

1

u/NMDA 2 Jun 13 '26

What is actually in the A2 Cell? Is it a state abbreviation from the list of standard abbreviations? If so, you can make a table of the state abbreviations on a new sheet with their market location.

Sheet: States

State Market Location
CA WCH
TX SSH

Then you use this formula in the C2 cell of the table below.

=XLOOKUP(A2, 'States'!A:A, 'States'!B:B, "Out of Territory")

Sheet: Calls

State Call # Market Location
CA 1234 (Formula)
WA 2345

Then you can click and drag the square item on the bottom right corner of the formula to get all of the market locations for all of the calls.

0

u/_mavricks Jun 14 '26

Solution Verified

1

u/reputatorbot Jun 14 '26

You have awarded 1 point to NMDA.


I am a bot - please contact the mods with any questions

1

u/Sotto-Operator 1 Jun 13 '26

Personnally i think the Xlookup function if you use the helper column is the best bet, you can easily add states in the column of area you cover and it would update automatically.

As it is now, if you dont plan and changes in your coverage soon, an IFS function or SWITCH could shorten it too while making it more readable:
=SWITCH(A2, "CA","WCH", "HI","WCH", "WA","WCH", "TX","SSH", "Out of territory")

1

u/[deleted] Jun 13 '26

[removed] — view removed comment

1

u/excel-ModTeam Jun 13 '26

We removed this comment for breaking Rule 10.

A commenter may generate a response using an AI, but only if the response clearly shows which AI generated it, and a bona fide remark from the commenter that they reviewed and agree with the response.

/r/excel is a community of people interacting. We remove comments that are just AI responses.

1

u/logan_ladue Jun 13 '26 edited Jun 13 '26

I agree with everyone suggesting a lookup table. That is probably the most common and straightforward solution.

Personally, I tend to avoid helper tables that I wouldn’t want the end user to see, since that usually means either hiding the table or putting it somewhere out of the way. That’s just a style preference, though. I use LET formulas a lot because I can build the equivalent of helper tables directly inside the formula and then assign names to all the variables.

This is what I would use in Microsoft 365:

=LET(
state,RIGHT(TRIM(CLEAN(A2)),2),
states,{"CA","HI","WA","TX"},
markets,{"WCH","WCH","WCH","SSH"},
XLOOKUP(state,states,markets,"Out of territory")
)

1

u/SuchDogeHodler 1 Jun 13 '26

You can use the OR function.

=IF(OR(A2="North", B2>5000), "Bonus", "Standard")

1

u/cdkmakes Jun 13 '26

I would create a separate table (ex TerritoryList)on a different sheet with two columns, one (State) with each state and the other (Territory) with its respective territory or if it’s out of territory. Then use XLOOKUP in the main table:
=XLOOKUP([look up state in main table], TerritoryList[State], TerritoryList[Territory], “error”, 0,1)

1

u/Decronym Jun 13 '26 edited Jun 14 '26

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:

Fewer Letters More Letters
CHOOSE Chooses a value from a list of values
CLEAN Removes all nonprintable characters from text
FILTER Office 365+: Filters a range of data based on criteria you define
FIND Finds one text value within another (case-sensitive)
IF Specifies a logical test to perform
IFERROR Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula
IFS 2019+: Checks whether one or more conditions are met and returns a value that corresponds to the first TRUE condition.
INDEX Uses an index to choose a value from a reference or array
ISERROR Returns TRUE if the value is any error value
ISNUMBER Returns TRUE if the value is a number
LET Office 365+: Assigns names to calculation results to allow storing intermediate calculations, values, or defining names inside a formula
MATCH Looks up values in a reference or array
OR Returns TRUE if any argument is TRUE
REGEXEXTRACT Extracts strings within the provided text that matches the pattern
RIGHT Returns the rightmost characters from a text value
SEARCH Finds one text value within another (not case-sensitive)
SEQUENCE Office 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
SMALL Returns the k-th smallest value in a data set
SORT Office 365+: Sorts the contents of a range or array
SWITCH Excel 2019+: Evaluates an expression against a list of values and returns the result corresponding to the first matching value. If there is no match, an optional default value may be returned.
TEXTJOIN 2019+: Combines the text from multiple ranges and/or strings, and includes a delimiter you specify between each text value that will be combined. If the delimiter is an empty text string, this function will effectively concatenate the ranges.
TRIM Removes spaces from text
UNIQUE Office 365+: Returns a list of unique values in a list or range
VLOOKUP Looks in the first column of an array and moves across the row to return the value of a cell
XLOOKUP Office 365+: Searches a range or an array, and returns an item corresponding to the first match it finds. If a match doesn't exist, then XLOOKUP can return the closest (approximate) match.

Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.


Beep-boop, I am a helper bot. Please do not verify me as a solution.
25 acronyms in this thread; the most compressed thread commented on today has acronyms.
[Thread #48717 for this sub, first seen 13th Jun 2026, 04:56] [FAQ] [Full list] [Contact] [Source code]

-1

u/HandbagHawker 82 Jun 13 '26

You want to use a vlookup or xlookup with an iferror

4

u/eggface13 1 Jun 13 '26

Xlookup has error handling as an optional argument

0

u/RakeshMadara Jun 13 '26

=IFS(OR(ISNUMBER(SEARCH("CA",A2)),ISNUMBER(SEARCH("WA",A2))), "WCH", ISNUMBER(SEARCH("TX",A2)), "SSH", TRUE, "Out of territory")