Sum only visibile cells using SUBTOTAL in Excel - excel

I'm intending to get the current balance of a stock using an Excel sheet. In this workbook, the balance is entered every day. However only the most recent day's balance is actually shown, all other are hidden. The data is entered in columns, and hence only one column of data is shown.
In this example, I want to sum the values from row 21 to 24. I enter the formula from the first documented balance, to some columns ahead in time (so the range does not need to be changed often).
For this I use:
=SUBTOTAL(109,C21:O24)
The last column's values sums to 20. However, using this formula sums to 260. It actually sums all values in row 21 to 24!
I confered the site https://support.office.com/en-us/article/SUBTOTAL-function-7b027003-f060-4ade-9040-e478765b9939 where it says that the value "109" should be used as the first argument in order to only sum non-hidden values. But evidently, this does not work. I also tried to use "9" as the first argument as well with the same result.
What is it that I am missing? Why doesn't this formula execute as intended?
MCVE (I reckon that if this is copied into cell A20, the value should become 260. When hiding all columns but A,B and O should give 20 using SUBTOTAL, but for me it still produces 260).
Stock
Prod1 5 5 5 5 5 5 5 5 5 5 5 5 5
Prod2 5 5 5 5 5 5 5 5 5 5 5 5 5
Prod3 5 5 5 5 5 5 5 5 5 5 5 5 5
Prod4 5 5 5 5 5 5 5 5 5 5 5 5 5 =SUBTOTAL(109;C21:O24)
Regards

From the documentation:
For the function_num constants from 1 to 11, the SUBTOTAL function includes the values of rows hidden by the Hide Rows command under the Hide & Unhide submenu of the Format command in the Cells group on the Home tab in the Excel desktop application. Use these constants when you want to subtotal hidden and nonhidden numbers in a list. For the function_Num constants from 101 to 111, the SUBTOTAL function ignores values of rows hidden by the Hide Rows command. Use these constants when you want to subtotal only nonhidden numbers in a list.
So that can't be used to sum cells hidden by columns.

Related

Removing several desired rows from excel sheet using the second sheet

How can I remove specific rows which has the same values in another excel sheet? of course there are many columns but I filter such that specific rows remained in the second sheet and we have those values in first sheet as well as other values. for example below I want to delete rows from second set with the same value in the first column of second set. rest does not matter
A B C
1 2 3
4 5 6
7 8 9
10 1 1
second set
A B C
1 5 6
3 3 9
7 7 6
This checks if the value in A2:A4 is in the other sheet in the A-column:
Formula used (I replaced the ´;´ with ´,´)
ISNUMBER(XLOOKUP(A2,Sheet2!$A:$A,Sheet2!$A:$A,"NOPE"))
The only thing left to do is filter by color and delete the rows. Though do remember that deleting rows in larger quantities, if they're not continuous, can be quite slow.

How to get max value in the column whilst counting and then reset count after reaching 0 and start to count until other max value is reached

I am trying to get the max value per run from my table. Each run lasts a different amount of days hence there will be a different max value for each run. My current table column Days looks like this:
Days:
1
2
3
4
5
6
7
8
0
1
2
3
4
5
0
1
2
3
4
5
6
7
8
9
10
11
0
1
2
3
I have another column called Max Day, where I want to get the max day per run from the above Days column, this is the output that I want to get at the end:
Max Days:
8
5
11
3
I have tried doing:
=COUNTIF(A$1:A1, A1) but that doesn't do anything, it just returns 0. Is there a way I can get the max value and then when it reaches 0, it starts counting again and retrieves the max value for that count and then repeat.
If you have Office 365, this is a piece of cake with the new Filter() function. In the screenshot, the formula has been entered into cell C2 and has NOT been copied down. It does that automatically.
=FILTER(A2:A31,A3:A32=0)
Edit - Explanation. For a general understanding of the new Excel Dynamic Array functions, please refer to this blog by the Excel team.
The Filter function returns all rows that match a given criterion. In this case the range to be filtered and the range in the criterion are offset by one row. The filter looks at rows 2 to 31, but the comparison looks at rows 3 to 32.
The effect is that the filter returns a value when the comparison is TRUE for the NEXT row, not the current row. Hence, the function returns all rows where the row FOLLOWING the current cell contains a zero.

Sum across columns based on 3 criteria

I'm trying to get a Sumif working across multiple rows.
For example, say my data source is below:
A B C
1 1 10 11
2 2 9 12
3 3 8 13
4 4 7 14
5 5 6 58
I want to sum from Columns A to C, in row 3. Output would be 24.
Ideally my criteria for the Horizontal Start, Horizontal End and Vertical would all be referenced in different cells which can be updated to get a new result depending on the criteria.
Is this possible so that the criteria cells can be updated and the formula will update accordingly?
Use a SUMIF, and betweem the logical criteria, simply use 3 criterias by seperating each with "&"'. This says that excel will sum if a happens, and b and c.

Summing a set of values based on cell content and row position

In the below table rows 2,3 and 4 have some details of a sporting event.
Range A2:C4 has a set of squad numbers and range D2:F4 has the details of who scored goals.
A B C D E F
1 Squad # Scorers
2 1 3 6 2 8 3
3 3 6 7 6 1
4 1 5 6 7 2 4
As an example squad # 6 has scored 8 goals based on the values equivalent position in the Squad section and relative to the Scorers range.
What formula will give me this total value and the equivalent total values for all squad numbers like the table below?
Some cells will be empty like F3.
1 9
3 14
5 2
6 8
7 0
A simple SUMPRODUCT function should take care of this.
=SUMPRODUCT($D$2:$F$4, --($A$2:$C$4=H2))
Fill down as necessary.
        
With only 3 games, the simplest way that I can see to do this would be to use 4 SUMIFS statements, as follows [assumes that your results data is in columns A & B, starting at row 5 and moving down; A5:A12 would hold the IDs for the different squads, and this formula would go in B5 and be copied down]:
=SUMIFS($D$2:$F$2,$A$2:$C$2,A5)+SUMIFS($D$3:$F$3,$A$3:$C$3,A5)+SUMIFS($D$4:$F$4,$A$4:$C$4,A5)
What it does is sum columns D:F, for row 1, row 2, and row 3, based on the fact that columns A:C for those rows match the appropriate squad ID.
This would be possible with an arguably shorter but more complex Array Formula, but with the data as you've presented it, I feel this is the clearest method.

Find maximum of row, return column name

I have four rows and six columns of random numbers between 1 and 10. The headers atop are named A through F accordingly. I want to populate a range (A1:A6) on another sheet with the maximum number for each row. That is easy with the MAX function. However, in a another range (B1:B6), I want to put the column name to which this number belongs.
An HLOOKUP() won't work because a maximum value in one row is likely not unique number across the entire sheet. I am thinking a MATCH INDEX type function, but my understanding of those functions, especially in conjunction, is poor.
A B C D E F
1 0 2 10 9 8
9 3 7 6 9 10
10 3 0 2 1 4
9 4 7 8 6 3
Assuming your array is in Sheet1 and the columns are labelled, please try in another sheet, copied down to suit (to Row4 since there are only four rows of numbers in your data):
=INDEX(Sheet1!A$1:F$1,MATCH(MAX(Sheet1!A2:F2),Sheet1!A2:F2,0))
This will return only the first column label from a row where the maximum for that row occurs more than once.

Resources