Sorry about the title of this question, I couldn't think of a better way of phrasing it.
I have a column with time ranges in it, i.e.
08:45-17:00
06:00-10:30
09:10-14:30
08:15-16:50
10:15-17:15
15:30-20:10
09:30-13:10
etc.
What I need is a count of those occurrences that cross a comparison time range. For example with a comparison range of 11:00-15:00, the count should include any in the column that:-
(1). has a start time OR end time between 11:00 and 15:00
OR
(2). starts BEFORE 11:00 AND ends AFTER 15:00.
In the examples above the count would be 5.
This formula gives the correct result (0 or 1) for individual entries:
=sum(if(or(and(mid(I14,7,5)>"15:00",mid(I14,1,5)<"11:00"),and(mid(I14,1,5)>"11:00",mid(I14,1,5)<"15:00"),and(mid(I14,7,5)>"11:00",mid(I14,7,5)<"15:00")),1,0))
There is probably a more elegant way of writing that!
Wrapping an arrayformula around that code doesn't work.
Any help much appreciated. Thanks in advance.
This is the GoogleSheets version of Ed's formula (thx Ed)
=arrayformula(counta(filter(H9:H44,or(and(left(H9:H44,5)<="11:00",right(H9:H44,5)>="15:00"),and(left(H9:H44,5)>="11:00",left(H9:H44,5)<="15:00"),and(right(H9:H44,5)<="15:00",right(H9:H44,5)>="11:00")))))
It seems that Filter doesn't like the use of "and" and "or" as it always returns 1 as the result, regardless of the entries.
I believe this does what you want. It uses counta and filter. The '+' are or and the '*' are and. I put the date ranges in A1:A7 so adjust to your range.
=arrayformula(COUNTA(FILTER( A:A ,(((right(A:A,5)>"15:00")*(left(A:A,5)<"11:00"))+(((left(A:A,5)>"11:00")*(left(A:A,5)<"15:00")))+(((left(A:A,5)>"11:00")*(LEFT(A:A,5)<"15:00")))+((right(A:A,5)>"11:00")*(RIGHT(A:A,5)<"15:00"))) )))
Related
I have a list of days and times in column A. Column B is a dollar value for each time value.
I want to get a specific time for each day and list the price in the next column. I have this right now:
The formula for column J is this:
=filter(A11:B,(mod(A11:A,1)*24)>=4.5,(mod(A11:A,1)*24)<=4.6)
This formula filters 4:30AM and the price associated with it.
Formula for column L is this:
=filter(A11:B,(mod(A11:A,1)*24)>=9.5,(mod(A11:A,1)*24)<=9.6)
Which filters only 9:30AM for each day and the price that goes with it.
As you can see, the dates stop matching when column J is 8/12/2021 and column L is 8/13/2021. This is because column L didn't have 9:30AM for 8/12/2021 so it skipped to 8/13/2021.
How can I make so that one of the columns skip a date if the other column doesn't match that time? I don't know if I explained that well but in the example above, column J should skip 8/12/2021 because column L didn't have 8/12/2021.
Another way of dealing with this issue is perhaps using UNIQUE and FILTER formulas but I'm not sure how that could be done. Any help would be greatly appreciated!
Here's a link to the spreadsheet: https://docs.google.com/spreadsheets/d/1TvP0_UsYJbLb5bscx2e4nTEnSkP5roBZpP8aIGdl414/edit?usp=sharing
I'm not 100% sure, but if you need to filter values so the time element is 09:30 and 04:30, then hide values where a date only occurs once (ie. no 09:30 value or no 04:30 value), you could use:
=arrayformula(filter(
filter(A11:B,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5)),
countif(int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))),int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))))>1)
)
Adjust >1 at the end to whatever logic you need (=2, <>1 etc).
You can also add sort() around everything if you need to.
Explanation:
It turns out that mod(A11,1)*24 doesn't round particularly well, so I suggest round(mod(A11:A,1)*24,2).
Therefore to filter the date/times for 9.30am and 4.30am, you can apply:
round(mod(A11:A,1)*24,2)=9.5
and
round(mod(A11:A,1)*24,2)=4.5
like this:
=arrayformula({filter(A11:B,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))})
filter is usually AND but to get OR condition it's filter(A:B,(A=1)+(A=2))
This gets the dates only:
=arrayformula(int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))))
Then this counts how many times a date appears:
=arrayformula(countif(int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5))),int(filter(A11:A,(round(mod(A11:A,1)*24,2)=9.5)+(round(mod(A11:A,1)*24,2)=4.5)))))
Combining the elements gets the solution.
I'll add a tab to your sheet.
You could filter each list on finding a match for each date (integer part of datetime) in the other list:
In J:
=filter(A11:B,(mod(A11:A,1)*24)>=4.5,(mod(A11:A,1)*24)<=4.6,isnumber(match(int(A11:A),int(filter(A11:A,(mod(A11:A,1)*24)>=9.5,(mod(A11:A,1)*24)<=9.6)),0)))
In L:
=filter(A11:B,(mod(A11:A,1)*24)>=9.5,(mod(A11:A,1)*24)<=9.6,isnumber(match(int(A11:A),int(filter(A11:A,(mod(A11:A,1)*24)>=4.5,(mod(A11:A,1)*24)<=4.6)),0)))
Note
Plz see Aresvik's answer for a possibly better approach to rounding, but note that 4:30 (3/16) actually has an exact representation as a binary decimal so rounding errors aren't an issue here.
I'm sorry to ask this, I have not any code skills and I've trying to figure that out for a few hours now.. I think an image will be better for you to understand what I want:
I want A2 to show the sum of the products in G:G that fit certain conditions (2020,jan,buy). I haved tried several formulas but I came up with this one as the closest, I think, but still won't work:
=arrayformula(SUMIFS(E:E=B1,F:F="jan",G:G="buy",H:H))
Can anyone explain me how to achieve that?
Thanks very much :)
Please use this formula in A2 it will work
=sumifs(G2:G100,D2:D100,2020,E2:E100,"jan",F2:F100,"buy")
So basically, sumifs formula is right one as you want to check for multiple conditions.
so this is how this formula work
=sumifs(sum_range,criteria_range1,criteria1,criteria_range2,criteria2,...)
In your case your same range is column 'G' so if you have a finite range like only 25 rows you have in your table then instead of G2:G100 you can use G2:G25 as G1 is containing label and make sure that all other ranges also similar to the range of column G. for example if you take range of G2:G100 means 99 rows then you should take E2:E100 or E3:E101(range of 99 rows, that rows must be 99 and series start and end number is as per your requirement, similar case for other columns in this formula)
you have to check 2020 in column D, so you criteria_range1 is of D column I took it D2:D100 and criteria 1 is 2020 as it's a number it doesn't need double quotes
criteria 2 is you need to check Jan in column E so criteria_range2 is column E I took it E2:E100 and criteria 2 is "jan" as it's not a number so I took it in double quotes.
criteria 3 is you need to check 'buy' in column F so Criteria_range3 is column F. I took it as F2:F100 and criteria 3 is "buy" again it's not a number so took it under double quotes.
So what i need is quite simple, yet somehow i cant get around to find a solution for it.
Basically what i need is for a column, starting from its 2nd row to look list numbers from 1 to 15 and have that sequence repeated all the way to the bottom of the sheet automatically. i was thinking about using arrayformula but couldnt figure out the formula for it.
essentially something like this but it goes all the way down automatically.
Explanation:
You can repeat (REPT) a sequence of numbers from 1 to 15 by using the Sequence formula.
The maximum number of times you want to repeat this sequence will be determined by the total number of rows in your sheet divided by 15.
Solution:
=transpose(split(REPT(concat(JOIN(",",SEQUENCE(1,15)),","),ROUNDDOWN(ROWS(A1:A)/15)),",",true))
Output:
non-REPT solution:
=INDEX(ARRAY_CONSTRAIN(FLATTEN(
SEQUENCE(ROUNDUP(ROWS(A:A)/15), 15)-(
SEQUENCE(ROUNDUP(ROWS(A:A)/15), 1, 0)*15)), ROWS(A:A)-ROW()+1, 1))
How can I simplify my code below without the hassle of updating the date every single day?
=COUNTIFS(Sheet2!A2:A5797,">=1/3/2019 7:00",Sheet2!A2:A5797,"<=1/3/2019 8:00",Sheet2!D2:D5797,"Resolved")
I should have a result when 3 conditions are met, like the time, date, and status(Resolved).
First I would suggest feeding the date-times as parameters, say:
=COUNTIFS(Sheet2!A2:A,">="&I1,Sheet2!A2:A,"<="&J1,Sheet2!D2:D,"Resolved")
so the results are determined by what you put in cells, rather than how you adapt a formula.
Then you might split dates and times as it seems it may only be the date you wish to change, thus say:
I1: =E1+F1 and J1: =G1+H1
where E1 and G1 are dates and F1 and H1 times.
Then if the times are always during the same day as one another: G1: =E1.
And if some automation is required, possibly:
E1:- =today(), or perhaps =today()+n, where n is an integer offset of choice.
I have an interval of data that seems like this:
I need to count how many Vs and how many Ds there are.
I already tryed with SUMIF and COUNTIF
Can someone help me?
Solution:
Join all the cells
Use Regex to replace everything other than the required character(ex.V) to null
Find the length of remaining string
Sample Formula:
=LEN(ARRAYFORMULA(REGEXREPLACE(JOIN(,A2:A9),"[^V]",)))
This Formula could also help. Just edit the range and letter according to the requirement here and you will get the exact number.
=ARRAYFORMULA(SUM(len(A$1:A)-len(SUBSTITUTE(A$1:A,"V",""))