SOLVED

Can I use an "IF" function to return a "0" if true and to perform a calculation if not true

Copper Contributor

Hello, I am attempting to write a formula which takes an inventory number which I input and compares it with what is expected to be on hand. If my count matches what is expected to be on hand then the gross sales would return a zero but if my hand count comes up less than what is expected to be on hand the formula would subtract what I counted from what is expected to be on hand and tell me the amount sold.

 

Ex. on my spreadsheet "gross inventory" is equal to opening inventory plus additional inventory received. That value is stored in cell G6. In cell H6 I input my physical count of inventory. So, if G6 = 500 and my count (H6) = 500 then I want I6 to =0. I can make that work fine on my sheet. But IF G6 (Gross inventory) is greater than H6 (hand counted inventory) I want I6 to compute the difference. So, cell I6 would either be 0 or the difference between G6 and H6. An

3 Replies
best response confirmed by Xnex66 (Copper Contributor)
Solution

@Xnex66 Something like this?

=IF(H6>G6,H6-G6,0)

This calculates H6-G6 if H6 is greater than G6. Anything else returns 0.

 

Or a more funky formula could be:

=(H6-G6)*--(H6>G6)

 

Thank you so much for taking time to help me out Riny, that worked like a charm and was much more simple and elegant than any monstrosities I was attempting to use.
1 best response

Accepted Solutions
best response confirmed by Xnex66 (Copper Contributor)
Solution

@Xnex66 Something like this?

=IF(H6>G6,H6-G6,0)

This calculates H6-G6 if H6 is greater than G6. Anything else returns 0.

 

Or a more funky formula could be:

=(H6-G6)*--(H6>G6)

 

View solution in original post