10 Advanced IF formula tricks you must know

Share

Facebook
Twitter
LinkedIn

IF is the most used Excel function out there. Here are 10 advanced IF tricks to take your formulas to next-level 🚀

In this article, you will learn:

  • Only one of, two out of three type rules
  • Between condition check with MEDIAN
  • Replacing Nested IF with shorter function
  • Using boolean logic to replace IF formulas
  • Arrays with IF function
  • Wildcard checks with IF function
  • How to use IF formula in other places
    • Conditional formatting
    • Data validation
    • Charts

Sample data for the examples

All examples in this article use below sample data. Assume it is in the range C8:G23sample-data-if-formula-advanced-tricks

You can download this data alone for practice purpose from here.

Includes sample data for practice, completed Excel workbook

#1 - Only one of condition

Situation

Identify employees who are only one of gender=male or salary under $85,000

Formula

				
					=IF(XOR(D8="Male",G8<85000),"Include", "Exclude")
				
			

Explanation

XOR function will return TRUE if an odd number inputs are TRUE, else FALSE. 

So, our XOR(D8=”Male”, G8<85000) will be useful for checking only one of condition.

Note: XOR doesn’t work when you want to check only one of when you have more than 2 conditions. For that refer to next trick.

Also read: Either Or formula in Excel

#2 - Two out of Three Check

Situation

Flag employees when they meet any two out of below three conditions.

  • Department is Website
  • Year of join is 2019
  • Salary is above $90,000

Formula

				
					=IF((E8="Website")+(YEAR(F8)=2019)+(G8>90000)>=2,
        "Include", "Exclude")
				
			

Explanation

The trick is in understanding Excel treats TRUE as 1 and FALSE as 0.

So, the expression (E8=”Website”)+(YEAR(F8)=2019)+(G8>90000)

will be converted a bunch of 1s & 0s and added up, depending on the details of employee.

We can then simply check if such number is >=2 to see if any two out of three conditions are met.

More: Two out of three – other ways to do it

#3 - Using MEDIAN for Between Condition

Situation

Identify employees joined between 1-Jan-2019 and 30-Jun-2019.

Formula

				
					=IF(MEDIAN(F8,DATE(2019,1,1),DATE(2019,6,30))=F8,
        "Review","")
				
			

Explanation

Normally, we use AND() function to check for between condition. But, you can also use MEDIAN for this. 

The pattern goes like,

=MEDIAN(your value, above, below) = your value

The above will be TRUE if your value is between above and below values.

For example, =MEDIAN(7, 3,9) = 7 is TRUE.

Read more: How to write BETWEEN formula in Excel

#4 - Replacing Nested IF functions

Situation

Calculate staff bonus based on below rules:

  • 1% for Website staff
  • 3 % for Sales staff joined in 2018
  • 2% for others

Formula

				
					=IFS(E8="Website",1%,
        AND(E8="Sales",YEAR(F8)=2018),3%,
        TRUE,2%)
				
			

Explanation

Nested IF functions can be hard to write and tricky to maintain. That is why, you should use the newly introduced IFS() function. 

The syntax for IFS goes like this:

=IFS(condition1, value1, condition2, value2…)

But, IFS() doesn’t have ELSE option…?

Well, you can use TRUE as last condition to fix this.

In the above formula TRUE, 2% part handles the ELSE case beautifully.

#5 - Boolean Logic to avoid IF formulas

Situation

Calculate staff bonus based on below rules, but don’t use any IF formulas:

  • 1% for Website staff
  • 3 % for Sales staff joined in 2018
  • 2% for others

Formula

				
					=2% - (E8="Website")*1% + AND(E8="Sales",YEAR(F8)=2018)*1%
				
			

Explanation

You can use boolean logic checks to altogether avoid IF formulas. This works well when your outputs are numbers.

The above formula calculates staff bonus by using TRUE=1 & FALSE=0 notion.

Let’s test it out for below staff:

boolean-replacement-if-sample-data

For Gigi:

  • 2% – (FALSE)*1% + (TRUE)* 1% = 3%

For Curtice:

  • 2% – (FALSE)*1% + (FALSE)*1% = 2%

Read more: Daniel Ferry’s excellent I heart IF

#6 - Checking if a value is in another list

Situation

Check if an employee is part of on call support team
(range: C32:C36)

Formula

				
					=IF(COUNTIFS($C$32:$C$36,C8),"On call","Not on call")
				
			

Explanation

We can use COUNTIFS or MATCH functions to do this. I prefer COUNTIFS.

Just count if a given data point is in another list.

Why don’t we check >0?

Remember, Excel treats any number other than 0 as TRUE. So we don’t need to write COUNTIFS($C$32:$C$36,C8)>0. 

#7 - Arrays with IF formula

Situation

Calculate median salary of website staff

Formula

				
					=MEDIAN(IF(E8:E23="Website",G8:G23))
				
			

Explanation

When you use arrays in the IF formula, it will return an array of outcomes too.

So for eg. =IF({TRUE,TRUE,FALSE}, {1, 2, 3}, {“A”,”B”,”C”}) will return {1, 2, “C”} 

We can use this powerful idea to calculate median salary of website staff too.

What about ELSE part? It’s missing no?

If you don’t mention the ELSE part of IF formula, it will simply return FALSE for those values.

So, in our case, we get 

{FALSE;90700;48950;FALSE;FALSE;107700;…FALSE}

When MEDIAN reads those values, it will ignore the FALSEs and calculate MEDIAN for rest.

Read more: Calculating RANKIFS with Excel

Situation 2

Show all names of “Finance” staff in one cell, comma seperated.

Formula

				
					=TEXTJOIN(",",,IF(E8:E23="Finance",C8:C23,""))
				
			

Explanation

This works same as the MEDIAN(IF()) structure. For more applications of this technique, see the Excel Risk Map

#8 - Wildcard based conditions

Situation

Identify if an employee’s name contains letters bo

Formula

				
					=IF(COUNTIFS(C8,"*bo*"),"bo person","not a bo person")
				
			

Explanation

IF function is not aware of wildcards. But we can use one of the other wildcard aware functions inside IF to solve the problem. You can use either of XLOOKUP, XMATCH, MATCH, VLOOKUP, COUNTIFS for this. 

I prefer COUNTIFS.

The COUNTIFS(C8, “*bo*”) will be 1 if name in C8 has bo in it, else 0.

Rest is self-explanatory.

Read more: Making VLOOKUP formula go wild | Not so wild lookups

#9 - IF formula with Conditional Formatting

Situation

Highlight employees that meet conditions specified in below cells.

input-rules for conditional formatting

Rule

				
					=AND($E8=$J$50,$D8=$J$51)
				
			

Explanation

When checking rules in conditional formatting you don’t need to use IF formula. Just use the condition part of the formula alone.

Here is the result of our rule.

result of conditional formatting

 

Read more: 5 simple & useful conditional formatting tricks

#10 - Using IF with Charts

Situation

Make a chart with employee salaries, but highlight staff making above average salary in a different color.

Process

  1. Add an extra column in your data and use IF formula to check if a person’s salary is above average.
  2. Make chart with both original salary & the new column.
  3. Overlap the bars (or columns) 100%
  4. Color them accordingly. 

Formula

				
					=IF(G8>AVERAGE($G$8:$G$23),G8,NA())
				
			

Outcome

This is how my chart looks.

highlighting staff with above average salary

Read more: How to highlight important points on your chart

Resources - File & Video

Includes sample data for practice, completed Excel workbook

Watch the video & learn these techniques

More on IF formula

Resources

Check out below tutorials to master IF formulas & business logic

Homework problems

What is your favorite IF formula trick?

Share it in the comments. Let’s learn from each other.

Facebook
Twitter
LinkedIn

Share this tip with your colleagues

Excel and Power BI tips - Chandoo.org Newsletter

Get FREE Excel + Power BI Tips

Simple, fun and useful emails, once per week.

Learn & be awesome.

Welcome to Chandoo.org

Thank you so much for visiting. My aim is to make you awesome in Excel & Power BI. I do this by sharing videos, tips, examples and downloads on this website. There are more than 1,000 pages with all things Excel, Power BI, Dashboards & VBA here. Go ahead and spend few minutes to be AWESOME.

Read my storyFREE Excel tips book

Overall I learned a lot and I thought you did a great job of explaining how to do things. This will definitely elevate my reporting in the future.
Rebekah S
Reporting Analyst
Excel formula list - 100+ examples and howto guide for you

From simple to complex, there is a formula for every occasion. Check out the list now.

Calendars, invoices, trackers and much more. All free, fun and fantastic.

Advanced Pivot Table tricks

Power Query, Data model, DAX, Filters, Slicers, Conditional formats and beautiful charts. It's all here.

Still on fence about Power BI? In this getting started guide, learn what is Power BI, how to get it and how to create your first report from scratch.

15 Responses to “Make a Bubble Chart in Excel [15 second tutorial]”

  1. Jeff Weir says:

    Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo!!

    • Chandoo says:

      Whyyyyyyyy?

      The idea is to tell how to make a bubble chart. I got an e-mail from a reader recently asking how the scatter bubble is made. So I thought a 15 second tutorial would be a good idea to show this.

  2. Jeff Weir says:

    Did that email go "Dear Chandoo, I know that you scorn bubble charts, but if I don't do one in Excel for my boss then he'll fire my sorry ass, and my children will have to be sold for medical experiments in order for me to be able to afford the upgrade path to Excel 2010"?

    If so, fair enough...it's all in the greater good 😉

  3. sanwijay says:

    Chandoo,

    I am using excel 2003 and it is not working. The x axis is not the one that I enter in x axis column. Please help! Thanks.

  4. sanwijay says:

    Sorry, after few attempts, I managed to get the right result. I shouldn't select the title (header) of the table and select only the data to produce the right bubble chart.

  5. Precious Roy says:

    What's wrong with bubble charts? Is there a better method for displaying scatter plots with lots of overlapping data points? Don't tell me you'd rather jitter!

  6. Chandoo says:

    @Sanwijay: Cool.

    @Precious Roy: There is nothing wrong with bubble charts. Infact, it is the only way to show 3 dimensional data (x,y and sizes) without confusing your audience. Jeff is worried that people might misuse the chart. As with any chart, bubbles also have a place and time for using them.

    I recommend using bubble charts to show relative performance various products in several regions and similar situations.

    Also, human eye is notorious in wrongly estimating the bubble sizes (as we have to measure areas). See http://chandoo.org/wp/2009/07/28/charting-lessons-from-optical-illusions/

    We can partially improve bubble charts by adding data labels, but if you have too many bubbles, the labels will clutter the chart and make it look busy.

  7. KW says:

    I can't seem to find a way to plot more than ten bubbles on a chart and need to know how to add more

  8. Chandoo says:

    @KW.. why would such a thing happen. I am sure you can add more bubbles that that. Can you tell us exactly what you are doing...

  9. Michiel says:

    Example table:
    A B C (size)
    Me: 25 30 15%
    Him: 30 22 11%
    Her: 12 30 20%

    I am trying to make a bubble chart where the Y axis is A, the X axis is B, and the size of the bubble is C. There should be only 3 bubbles. I keep ending up with six (with the labels being only "Me" and "Her"). My goal is to have three bubbles, one representing each person. Clearly I am doing something wrong. Can you help explain...?

  10. Priya says:

    Hi,
    I wanted to add data labels to the bubbles. Each bubble represents a different company name. Excel allows me to add the size, legend, x axis values and y axis values. How do I add instead- Company A, B, C, D for the bubbles?

    • Mai huong says:

      youon you have to choice every data for every company..
      ex:create bubble for A company,after that click right> add data label> adjust data labels :format data labels and choose : series name.
      i hop u will succeed .

  11. [...] we create a bubble chart with 2 bubbles. 1 for the actual mustache & 1 for target [...]

  12. IT says:

    If we want bubble size to be controlled by one column, but the bubble labels to be controlled by another column, how can this be achieved?

  13. Nicola says:

    many thanks!!!!

Leave a Reply