SUBTOTAL where dates are between a range - excel

im doing some calculations in excel and noticed there were way off what i was expecting i was using this formula calculate the sum for values between a date range:
=SUMIFS(V496:V57573,U496:U57573,">"&"01/01/2020",U496:U57573,"<"&"29/02/2020")
i think i should be using the SUBTOTAL to do it on the filtered data so i get the result for that subset.
How would i use the subtotal to have it where its in that date range on an already filtered data set

Iterate the rows and check if hidden, then use some Boolean with SUMPRODUCT.
=SUMPRODUCT((SUBTOTAL(2,OFFSET(V496,ROW($ZZ1:INDEX($ZZ:$ZZ,ROWS(V496:V57573)))-1,0,1,1)))*(U496:U57573>DATE(2020,1,1))*(U496:U57573< DATE(2020,2,29))*V496:V57573)

Related

Excel COUNTIFS between date range

How do I count between a date range using COUNIFS? The dates are set as columns The_Date_Start and The_Date_End.
My formula is
=COUNTIFS(Sheet2!C:C,[#Tel],Sheet2!A:A,"<="&[#[The_Date]])
I have tried something like the below but doesn't work
=COUNTIFS(Sheet2!C:C,[#Tel],Sheet2!A:A,"=>"&[#[The_Date_Start]],"<="&[#[The_Date_End]])
You can use this formula:
=COUNTIFS([ColToCount], ">="&[#End], [ColToCount], "<="&[#Start])
Note that all the ranges should be of same length. In your formula, they are of different lengths

Sum a list of indirect ranges from a dynamic range

I have a list of ranges in a column. The ranges are part of a dynamic named range and are in text format.
$A$1:$A$5
$A$6:$A$10
$A$11:$A$15
...
The aim is to SUM the values between each range in the dynamic range as calling the dynamic range should iterate through all the ranges. However, does not with =SUM(INDIRECT(<dynamic_range>). This formula only returns one value which does not correspond with the first range in the dynamic range.
For example, return the sum of the first range, then in the next row, return the sum of the second range, so on and so forth until the end of the dynamic range.
I am trying to keep this preferably as a formula and not in VBA.
Use SUMIF not SUM with the dynamic array formula in Office 365 it will spill the sums:
=SUMIF(INDIRECT(rng),"<>")
Avoiding volatile INDIRECT you can use:
=SUM(INDEX($A:$A,SEQUENCE(5,,ROW()*5)-4)) when you have office365 or =SUM(INDEX(A:A,ROWS($1:1)*5-4):INDEX(A:A,ROWS($1:1)*5)) for older versions.
PS this is provided that the change of range is in same steps of 5 cells each time.

Return non-blank rows from a range in a new range list in Excel

Using Excel, assumed there is a range of data including text and number values. But some are blank rows. How could I create a range of list which only includes non-blank rows using Excel functions? Thus, I don't have to copy, paste and remove blank rows by daily.
For example, Raw data table as below,
AAA 111 111 111 111
BBB 111 111 111 111
AAA 111 111 111 111
CCC 111 111 111 111
QQQ 111 111 111 111
SSS 111 111 111 111
BBB 111 111 111 111
Then, create a new range of table like this,
AAA 111 111 111 111
BBB 111 111 111 111
AAA 111 111 111 111
CCC 111 111 111 111
QQQ 111 111 111 111
SSS 111 111 111 111
BBB 111 111 111 111
I was trying to use this formula. However, it doesn't work...
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F1:J1))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F2:J2))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F3:J3))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F4:J4))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F5:J5))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F6:J6))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F7:J7))),"")}
IF($A$1:$E$12<>"",ROW($A$1:$E$12)) in array context will result in a row vector {1,1,1,1,1} in case of row 1. So it always results in 5 times either the row number or FALSE for each row. So you will get each not empty row number 5 times.
One option would be only checking if column A is empty and having the array formula for each single cell instead of the single rows:
{=INDEX($A$1:$E$20,SMALL(IF($A$1:$A$20<>"",ROW($A$1:$A$20)),ROW(1:1)),COLUMN(A:A))}
Example:
Of course this is really not performant for big ranges. But I don't see another possibility using formulas.
What I would do is having a helper column using the array formula:
{=AND(A1:E1<>"")}
for each row.
And then sorting the table by this helper column descending.

Calculate the COUNTIFS criteria range dynamically

I have a excel formula as below,
COUNTIFS($A$8:$A$14,$A8,$B$8:$B$14,$B8)
Here I want the criteria range to be calculated with a simple logic.
Instead of $A$14 I want this value to be calculated A$8+4 i.e. $A$14
In other words, it should get the current row and add 4 to be the criteria range for COUNTIFS
How can this be done is excel within the COUNTIFS formula?
Cheers
You could use =OFFSET(Cell Reference, Rows, Columns) within your formula to achieve this, for example:
=COUNTIFS($A$8:OFFSET($A$8,6,0),$A8, etc...)
Lets assume that the size of your range to be returned is stored in the cell D1.
=COUNTIFS($A$8:INDEX(A:A,ROW($A$8)+D1),$A8,$B$8:INDEX(B:B,ROW($B$8)+D1),$B8)
If you want the range to be defined as a certain number of rows after the current row as stated in your question, then still assuming the number of rows to be added is in D1, you would use the following:
=COUNTIFS($A$8:INDEX(A:A,ROW()+D1),$A8,$B$8:INDEX(B:B,ROW()+D1),$B8)
Expanding on Oliver's answer. The full format of OFFSET allows you to specify a whole range, not just one cell. OFFSET(Reference, Row Offset, Col Offset, Height, Width) so you could do:
OFFSET(A8,0,0,4,1)
This specifies the range A8:A11. In the COUNTIF
=COUNTIF(OFFSET(A8,0,0,4,1),A8,...)
Locking cells with $ works the same way within OFFSET if needed.
Try this:
=COUNTIFS(INDIRECT("$A$8:$A$" & 8+6),$A8,INDIRECT("$B$8:$B$" & 8+6),$B8)

Add total SUM from VLOOKUP?

I've got 3 columns as follows:
Boolean Value Date
Yes £3000 01-Jan-2012
No £3000 01-Jan-2012
No £3000 01-Nov-2012
Basically I just need to look at that table and come up with the total value for where Boolean is set to No, however only take those where the month is equal or less than the current month set by the computer time
Which version of Excel? In Excel 2007 and later try SUMIFS which allows you to sum with multiple conditions, i.e.
=SUMIFS(B2:B10,A2:A10,"No",C2:C10,"<="&TODAY())
I used cell references but you can used named ranges in their place like this:
=SUMIFS(Value,Boolean,"No",Date,"<="&TODAY())
or in earlier versions of Excel you can use SUMPRODUCT like this:
=SUMPRODUCT(B2:B10,(A2:A10="No")*(C2:C10<=TODAY()))
Use the DSUM function.
Criteria range would be
Boolean Month Check
No =MONTH(C2) < X
where C2 is the first data cell in column Date.

Resources