CountIF error with <0 - excel

I would need some help again with another excel countif expression. I have the line i2:al2 which contains leftover stock data.I am building a worksheet to calculate remaining stocks in % as per supervisor's wish.
As I am working with %, for example if I say that 90% sales that means we have 103 stock left and with 91% sales I have 100 stock left.
Anyways I got around to count the number of stock left in line i2:a12 using countifs.
Example if I need to calculate leftover stock for sales at 90% which means leftover stock level of 100 to 102. I have used :
=countif(range,">100")-countif(range,">102")
This method seems to work till I reach negative numbers, i.e. oversales. For example, if I try to do the following:
=countif(range,"-100")-countif(range,">0")
the formula seems to stop working. If I count manually using a conditional formatting I get a totally different answer for the oversales.
Maybe I am getting the logic of the countif function wrong. My purpose for the expressison is:
=count(in range, values >=X & <=Y)
As I have only access to excel 2003 I cannot use Countifs method. Anyone could help me on this issue?
Many thanks.

You can use an array formula:
=SUM((range>=x)*(range<=y))
For that to work, you need to press CTRL-SHIFT-ENTER for that to use array formula.
Alternatively, using what simoco gives in the comment works too without having to save as array formula.

Related

Execute excel formula only for specific cells

I am trying to create a formula that checks for several things at the same time but I am having trouble with one part of it.
The formula is the following:
=IF(COUNTIFS($N$2:$N$17095,N3,$K$2:$K$17095,"<>"&"")>6,
IF((SUMPRODUCT(--(ROUND($K$2:$K$49,2)=ROUND(K3,2)))>9),"Always Late / Possible Automation",
IF(COUNTIFS($N$2:$N$17088,N3,$K$2:$K$17088,"<3.5")>0,"Delivered Earlier At Least Once",IF(COUNTIFS($N$2:$N$17088,N3,$K$2:$K$17088,">3.5")>6,"Always Late","False"))))
The first part checks how many entries in the range having the same value as it is in cell N3 have values different to blank and we want those to be more than 6.
Second part is the tough one, it is supposed to check how many values in the rounded range match the rounded value in cell K3. The issue is the formula checks the whole range and I want to check only for the values which match N3 (in essence like the CountIf works only for that value).
The rest is not so relevant.
Some example data:
![enter image description here][1]
As you see in the end of the table the formula with the rounding works but only because I have limited the data shown to 3 unique values in column N. Even here though if i have a blank it doesnt work becaus ei haven't considered it.
Thanks in advance.
Assuming you have Office 365 compatibility/Excel version, use a bunch of filters. To avoid an unwieldy formula I've extended ranges to maximum number of rows (customize as required)...
=LET(x_,$E$3:$E$25,a_,FILTER($E$3:$E$25,--(x_=E3)),b_,FILTER($B$3:$B$25,--(x_=E3)),IF(SUM(--(a_=E3)*(b_<>""))>6,IF((SUMPRODUCT(--(ROUND(b_,2)=ROUND(B3,2)))>9),"Always Late / Possible Automation",IF(SUM(--(a_=E3)*(b_<3.5))>0,"Delivered Earlier At Least Once",IF(SUM(--(a_=E3)*(b_>3.5))>6,"Always Late","False")))))
Note: filter does not appear to work too well within countifs for some reason (must be related to syntax RE: arrays vs. criteria TBC). Thus have replaced countifs(filter_range,X) eqn 'types' with sum(--(filter_range=X)) which works as intended.

Ranking formula in excel based on two columns

I'm trying to rank the following items based on price using the following formula =SUMPRODUCT(([Item]=[#Item])*([#Price]<[Price]))+1, but it isn't returning any results:
When I use the same formula in the following test table it works, =SUMPRODUCT(($A$2:$A$7=A2)*(B2<$B$2:$B$7))+1:
Can someone please let me know what I am doing wrong? Thanks
EDIT 2 : Evaluation https://imgur.com/a/eXIYPAP
Your formula works fine for me.
Are you sure that A2 and A3 are the same value? There may be some hidden white space causing problems. Just try
=A2=A3
in another cell to make sure they are the same.
USE COUNTIFS INSTEAD
I don't know why your formula isn't working, however, I would suggest avoiding SUMPRODUCT where you can.
=COUNTIFS([Item],[#Item],[Price],">"&[#Price])+1
This will count the number of prices higher than the current one for each item (+1, if you want the rank to start at 1 instead of 0)
If your goal is to get the ranking for each unique item, =SUMPRODUCT(([Item]=[#Item])*([Price]>[#Price]))+1 should do the trick. If the goal is to get the ranking based only on price, don't have it figured out yet.

How to best find the minimum positive difference of a value compared to a table efficiently using one Excell cell only?

I want to avoid VBA as much as possible and try to find a solution in a single cell--if possible. I have been trying to find a way to do so, but I have no idea how to.
The logic is summarized in the image below. In words, the conditions are:
Search Name is looked for in the Name column of the right table.
Search Date has to be greater than the Date in the right table.
Search Date minus Date has to be the positive minimum value.
Return the Pay that matches the criteria--which is 500 in the example.
You could use the following array formula (i.e. you need to enter it with Ctrl+Shift+Enter, if you are successful, you will see the braces appear in the formula bar):
=INDEX(G:G,MATCH(A2,IF(F:F=B2,E:E)))
The formula will return #N/A if there are no dates earlier than the Search Date.
NOTE: The dates have to be sorted in ascending order for this to work
EDIT: A little more robust that doesn't require sorting:
=INDEX(G:G,MATCH(MAX(IF((F:F=B2)*(E:E<A2),E:E)-A2),IF((F:F=B2)*(E:E<A2),E:E)-A2,0))
Note: Since this doesn't use MATCH, you won't get #N/A in case there are no dates earlier than the Search Date and you will instead get Pay (i.e. the header). If you want to get something else, then you can wrap the whole function in an IFERROR, relying on the fact that excel returns an error if one attempts to multiply a text with a number, something like this:
=IFERROR(Formula*1, "No pay matched")
This can be done with SumProduct, which does not require Ctrl-Shift-Enter
=SUMPRODUCT($G$2:$G$9,(A2>$E$2:$E$9)*(MONTH(A2)=MONTH($E$2:$E$9)*($F$2:$F$9=B2)))
The logic commands that the Search Date is in the same month as the Date column.
If you have the new Dynamic Array functions, that are currently in preview in the Insider Fast build of Excel 365, you can use
=FILTER($G$2:$G$9,(A2>$E$2:$E$9)*(MONTH(A2)=MONTH($E$2:$E$9)*($F$2:$F$9=B2)))

COUNTIF formula counts values that don't match

I'm using counting invoice numbers (text) in a table's column, but the Excel formula seems to be confusing some values.
I copied small sample of these - please refer to below:
The formulas are as follow:
=COUNTIFS(A1:A19,A1)
=COUNTIF(A1:A19,A1)
As you can see these invoice numbers differ and the results of these functions suggest as if all were the same.
I googled it for 1 hour but I didn't find such as issue as mine.
If anybody had any clue why could this behave in such way I'll be super grateful!
Rob
Each time you copy down this formula it will add 1 row to each. For example the second row of datas formula will be =COUNTIFS(A2:A20,A2). To lock these cells in the formula use $
Your formula should be =COUNTIFS(A$1:A$19,A1)
I've solved this myself:
ROOTCAUSE
Excel tried to be helpful and read these invoice numbers as actual numbers (despite these being defined already in Power Query as text)
Then, Excel fooled me and despite showing that it works on it as a string (I was evaluating the formula) it worked on it as number
Above means that it transformed exemplary "00100001010000018525" to 1.00001E+17, which cut down this to "100001010000018000" - that's the moment Excel stopped fooling around and showed that value in the formula bar.
I think I don't need to tell why countif perceived all these values as equal.
SOLUTION
I simply appended one letter after each invoice number to get e.g. "00100001010000018525a" what forces Excel to quit its gimmicks and games.
Case closed.
I suspect this is a bug in COUNTIF, or maybe by design.
However, to workaround this in the formula, without having to change your data, try adding a wild-card character:
=COUNTIF(A1:A19,"*"&A1)

Using `SUMPRODUCT` without dividing by zero

See the image above for my hypothetical grade sheet in Libre Calc. There are two rows. One contains the points achieved for each assignment while the second records the points available. I would like to keep a running average of the grades, but I do not wish to update the formula for the running average each time a new assignment is added. Currently, I am using:
SUMPRODUCT( ENTIRE_POINTS_ACHIEVED_ROW, 1 / (ENTIRE_POINTS_AVAILABLE_ROW) )
I then find the average by dividing by the number of non-blank rows, using COUNTA().
As you can see above, assignments 1-3 are complete, but there is no information for the fourth. Because of this, I get a divide by zero error. How can I accommodate for this? Or, is there a more straightforward way to achieve what I've described above?
As Scott Craner proposed , using an Array formula is the way to follow. With LO Calc, the following formula should work (enter it with CTRL+SHIFT+ENTER to make it an array formula):
=SUMPRODUCT(IF(B2:E2<>0; B2:E2; "");1/B3:E3)/COUNT(B2:E2)*100
I've adapted an example from the OpenOffice.org Calc documentation for this.
Use this array formula instead:
=SUM(IF($B$3:$E$3<>"",B2:E2/B3:E3))/COUNT(B2:E2)
Being an array it must be confirmed with Ctrl-Shift-Enter. If done properly {} will be put around the formula.
This is excel, It may not work in LibreOffice.

Resources