Converting some MySQL into formula

slam

Well-known Member
Joined
Sep 16, 2002
Messages
873
Office Version
  1. 365
  2. 2019
This is a simplified version of what I have in MySQL that I'm struggling to turn into a formula:

SQL:
IF C2 < B2 * 1.01 AND C2 - B2 > 20000 then "Over Budget"

IF C2 > B2 * 1.01 AND C2 - B2 > 5000 then "Over Budget"

else "Under Budget"

What I have so far is this (and I know I still need to add the 2nd line in):

Excel Formula:
=IF(AND(C2<=(B2*1.01),C2-B2>=20000),"Over Budget","Under Budget")

It's marking everything as Under Budget, which shouldn't be the case. Can someone identify what I've done wrong?

Thanks!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
try the and() in a cell and see if you get true or false and change some values
you probably need a nested IF

IF C2 < B2 * 1.01 AND C2 - B2 > 20000 then "Over Budget"

IF C2 > B2 * 1.01 AND C2 - B2 > 5000 then "Over Budget"

OR
AND(C2>=(B2*1.01),C2-B2>=5000)

=IF(OR( AND(C2<=(B2*1.01),C2-B2>=20000), AND(C2>=(B2*1.01),C2-B2>=5000)),"Over Budget","Under Budget")

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

This will possibly enable a quicker and more accurate solution for you.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC

then put the sample spreadsheet onto a share

I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed

Make sure you set any share or google to share to everyone
 
Upvote 1
Solution
Try changing your "AND" to "OR", i.e.
Excel Formula:
=IF(OR(C2<=(B2*1.01),C2-B2>=20000),"Over Budget","Under Budget")
 
Upvote 1

Forum statistics

Threads
1,215,356
Messages
6,124,471
Members
449,163
Latest member
kshealy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top