AverageIFS formula to take the average starting with the first positive number and last positive number and include any zeros in that range - excel-formula

I need a dynamic AverageIFS formula that will start taking the average with the first positive number and end the average at the last positive number. I need the formula to include zeros in the average if there are any in between the first and last positive number. Using the attached image as an example, I want the average_range to be Dec-21 through Nov-22 but I only want the Average to calculate Dec-21 through Jul-22 since that range contains the first and last positive numbers. The average number I'm looking for based on the numbers provided is 1.375. Thank you all for your help!
I tried the AverageIFS function but I'm not having any luck. I know I'm doing something wrong but not sure what.

we can use two indexes, and xmatch which allows us to search backwards and forwards.
=AVERAGE(INDEX(A2:L2,XMATCH(TRUE,A2:L2>0,0,1)):INDEX(A2:L2,XMATCH(TRUE,A2:L2>0,0,-1)))
If one does not have XMATCH the we can use MATCH for the first and AGGREGATE for the second:
=AVERAGE(INDEX(A2:L2,MATCH(TRUE,A2:L2>0,0)):INDEX(A2:L2,AGGREGATE(14,7,(COLUMN(A2:L2)-MIN(COLUMN(A2:L2))+1)/(A2:L2<>0),1)))
Another Note:
With older versions one may need to use Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Related

Min - second lowest number using non adjacent ranges

I understand the min formula as a standard and have created the below formula to find the min value across to non adjacent ranges
=MIN(G14:I12, K14:M14)
But what I need is to find the second smallest number but am experiences many errors
=MIN((G14:I12, K14:M14),2)
this returns the value of 2, and if i add indirect I receive an error, any thoughts on the correct way of finding the second lowest number from non adjacent ranges?
=MIN(INDIRECT(("G14:I12", "K14:M14"),2))
If you want second minimum number then could try SMALL() function. Try-
=SMALL(G2:M2,2)

Formula to find n numbers occuring together in a cell

I would like to ask whether it is possible to create formula in Excel that extracts n first numbers in certain cell but only if these numbers are next to each other (in a group).
For instance for RegExp we can write \d{8} which in string:
abc1234_123456789012abc_87654321000_abc
finds groups of every eight numbers occuring together no matter how many times they occur:
abc1234_123456789012abc_87654321_000abc
I would like to achieve similar effect (it may be even the first occurrence, not every) without using VBA (RegExp) and to have ability to easily change number of digits taken into account, i.e. from another cell, not by expanding the formula with additional functions.
Thank you in advance.
With Microsoft365, you could try:
For all overlapping values in C1:
=LET(A,MID(A1,SEQUENCE(LEN(A1)),B1),B,IF(ISNUMBER(--A),A,""),FILTER(B,B<>"",""))
For all non-overlapping sequences in D1:
=LET(A,B1,B,MID(A1,SEQUENCE(LEN(A1)),1),C,FILTERXML(SUBSTITUTE(TRIM(CONCAT("<t><s>'",IF(ISNUMBER(--B),B," "),"</s></t>"))," ","</s><s>'"),"//s"),D,FILTERXML("<t><s>"&TEXTJOIN("</s><s>",,MID(C,SEQUENCE(1,LEN(A1),2,A),A))&"</s></t>","//s[string-length()="&A&"]"),TEXT(D,REPT(0,A)))
The 2nd option got quite long since I needed to find a way to prevend false positives when I checked if preceding tokens were numeric etc. But you'd only now need to change the value in B1 to whichever number you'd like to find the non-overlapping values. For example:
To simply get the first occurence of any 8 digits, try:
=IFERROR(MID(A1,MATCH(1,INDEX((ISNUMBER(--MID(A1,ROW(A$1:INDEX(A:A,LEN(A1))),B$1)))*(LEN(MID(A1,ROW(A$1:INDEX(A:A,LEN(A1))),B$1))=B$1),),0),B$1),"Not Found")

Sum of Small number in the given range ignoring Character in Array, Excel

I am trying to sum the small number in an array which has both number and letters.
Row values are like: 1,NA,B,0,-1,NA,-1.
In this range i am trying to sum least 5 numerical values, since there is only 4 numerical values
i am getting error. please let me know how this can be done to ignore alphabets.
here is the formula i am using
{=SUM(SMALL(A1:G1,ROW(INDIRECT("1:5"))))}
also i tried
{=SUM(SMALL((ISNUMBER(A1:G1)),ROW(INDIRECT("1:5"))))}
Thanks
You need to use COUNT with MIN to set the last:
=SUM(SMALL(A1:G1,ROW($ZZ$1:INDEX($ZZ:$ZZ,MIN(COUNT(A1:G1),5)))
Depending on ones version the may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
I changed the INDIRECT to INDEX to remove the volatility of the function.
If you do not care about the volatility just replace "1:5" with "1:" & MIN(COUNT(A1:G1),5) in your formula. But I would not recommend it, as volatile function will calculate every time there is a change in Excel causing unneeded calculations.

How to find average consecutive positive number in excel?

Hi all,
I want to find the average consecutive positive number from row 12 to row 31. Is there any way to calculate it without extra column D?
Use Frequency:
=AVERAGE(IF(FREQUENCY(IF(C12:C32>0,ROW(C12:C32)),IF(C12:C32>0,"",ROW(C12:C32)))>0,FREQUENCY(IF(C12:C32>0,ROW(C12:C32)),IF(C12:C32>0,"",ROW(C12:C32)))))
Depending on one's version this may require the use of Ctrl-Shift-Enter instead of Enter when exiting edit mode.

Need a formula to determine the maximum number of days between multiple consecutive dates

I have a string of consecutive dates in an excel table that represent when items were picked up from a store. I need to determine either if any gap is more than 60 days or the greatest gap. Example:
9/5/18, 9/18/19, 11/20/18, 12/21/18
The gap between the 2nd and third dates is the greatest at 63. I either need the "63" or a "yes" if >63. I have a few hundred rows of these dates so looking for a formula without the need to build helper tables.
Thanks in advance.
IF the dates are in different cells:
=MAX(B1:D1-A1:C1)>60
Depending on one's version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If they are in the same cell, comma delimited:
=MAX(FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b["&ROW($ZZ$2:INDEX($ZZ:$ZZ,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1))&"]")-FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b["&ROW($ZZ$1:INDEX($ZZ:$ZZ,LEN(A1)-LEN(SUBSTITUTE(A1,",",""))))&"]"))>60
Depending on one's version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If the dates are all in a single cell, and you have a recent version of Excel with the SEQUENCE function, you can use:
=AGGREGATE( 14,6,DATEVALUE(TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",99)),SEQUENCE(10)*99,99)))-DATEVALUE(TRIM(MID(SUBSTITUTE(A1,",",REPT(" ",99)),IF(SEQUENCE(10)=1,1,(SEQUENCE(10)-1)*99),99))),1)
where the 10 argument for SEQUENCE is just some value greater than the total possible number of included entries.
If you do not have the SEQUENCE function, you can use something like:
=ROW(INDEX($A:$A,1,1):INDEX($A:$A,255,1))
I prefer to make that a named formula, and name it seq, so the final formula would look like:
=AGGREGATE( 14,6,DATEVALUE(TRIM(MID(SUBSTITUTE(A3,",",REPT(" ",99)),seq*99,99)))-DATEVALUE(TRIM(MID(SUBSTITUTE(A3,",",REPT(" ",99)),IF(seq=1,1,(seq-1)*99),99))),1)
Date-Times in excel are in days since the epoch, floating point, with a presentation number format that you can adjust (I like YYYY-MM-DD iso date). It should be easy to convert your strings to dates, if they are not already dates by automatic conversion. I bet there is a function for that! Subtract them, but since the are date-time floating point numbers with fractions, you might need to find a function named int or integer to scrape off any fraction. Of course, if they all lack time components, that part defaults to the same time, so the subtraction returns whole days.

Resources