Reset a cumulative total when 0 is entered - excel

I have a column that numbers are entered and the column next to it calculates the cumulative total.
|...| H | I |
1 |...| | |
...|...| | |
16 |...| 100 | 100 |
17 |...| | |
18 |...| | |
19 |...| 100 | 200 |
20 |...| 100 | 300 |
21 |...| | |
22 |...| 100 | 400 |
...|...| | |
I am using this in the first cell
I16 = =IF(H16="","",H16).
The following cells in the column are,
I17 = =IF(H17="","",SUM($H$16:H17)),
I18 = =IF(H18="","",SUM($H$16:H18))
I19 = =IF(H19="","",SUM($H$16:H19))
and so on.
I would like the reset the cumulative total in column I to 0, if there's a 0 entered column H.
The simple solution is taking the value in H and add it to I but that doesn't work if there's no values entered, which is common, like in the example. So, something like =IF(H17=0,0,I16+H17) and so on will not work as a null would miscalculate the cumulative total.
I would like the end result to look like this;
|...| H | I |
1 |...| | |
...|...| | |
16 |...| 100 | 100 |
17 |...| | |
18 |...| | |
19 |...| 100 | 200 |
20 |...| 0 | 0 |
21 |...| | |
22 |...| 100 | 100 |
...|...| | |
I'm open to any ideas to accomplish my task.
Thank you for your time.

An INDIRECT ADDRESS Helper Column Solution
The second formula is (sadly) just for cell J16, the others are to be copied down. The formulas in column J can be Cut/Pasted to another column.
[I16] =IF(H16="","",SUM(INDIRECT(J16&":"&ADDRESS(ROW(H16),COLUMN(H16)))))
[J16] =ADDRESS(ROW(H16),COLUMN(H16))
[J17] =IF(H17="",J16,IF(H17=0,ADDRESS(ROW(H17),COLUMN(H17)),J16))
BTW, in your current setup you can safely copy the formula from I17 to I16. There is no need for different formulas.

Related

SUM values in one column if criteria exists at least once per value in another column

| A B C D | E F | G H
----|----------------------------------------------------|-----------------------|-------------------
1 | | |
2 | Products date quantity | |
----|----------------------------------------------------|-----------------------|-------------------
3 | Product_A 2020-01-08 0 | From 2020-01-01 | Result: 800
4 | Product_A 2020-12-15 0 | to 2020-10-31 |
5 | Product_A 2020-12-23 0 | |
6 | Product_A 500 | |
----|----------------------------------------------------|-----------------------|------------------
7 | Product_B 2020-11-09 0 | |
8 | Product_B 2021-03-14 0 | |
9 | Product_B 700 | |
----|----------------------------------------------------|-----------------------|------------------
10 | Product_C 2020-02-05 0 | |
11 | Product_C 2020-07-19 0 | |
12 | Product_C 2020-09-18 0 | |
13 | Product_C 2020-09-25 0 | |
14 | Product_C 300 | |
14 | | |
15 | | |
In the table I have listed different products with multiple dates per product.
Below each product there is a row in which a quantity is displayed.
Now in Cell H3 I want to get the Sum of the quantity of all products that have at least one date between the dates in Cell F3 and Cell F4. In the example this applies to Product_A and Product_C therefore the sum is 500+300=800.
I have no clue what kind of formula I need to achieve this.
I guess it must be something like this:
SUMIFS(Date in Cell F3 OR in Cell F4 exists for Product in Column C THEN SUM over Column D)
Do you have an idea how this formula has to look like?
One way would be with SUMPRODUCT() combined with COUNTIFS():
=SUMPRODUCT((COUNTIFS(B3:B14,B3:B14,C3:C14,">="&F3,C3:C14,"<="&F4)>0)*D3:D14)

Sum of max in Excel Pivot Table

Please do not mark this as duplicated of Sum of Max in PivotTable for Excel because there is no even answer for it.
I have a pivot table of items grouped by ID and month, and getting the maximum Q among all items. So the totals get the maximums as well.
+------------+---------+----------------+
| A | B | C |
+-+------------+---------+----------------+
|1| Month | ID | Max(Q) |
+-+------------+---------+----------------+
|2| 1 | A | 23 |
+-+------------+---------+----------------+
|3| 1 | B | 11 |
+-+------------+---------+----------------+
|4| Subtotal 1 | 23 |
+-+------------+---------+----------------+
|5| 2 | C | 85 |
+-+------------+---------+----------------+
|6| 2 | D | 6 |
+-+------------+---------+----------------+
|7| Subtotal 2 | 85 |
+-+------------+--------------------------+
|8| Total 85 |
+-+---------------------------------------+
What I want to do is still get the max of each ID, but the totals to be the sum of the maximums. Like the following.
+------------+---------+----------------+
| A | B | C |
+-+------------+---------+----------------+
|1| Month | ID | Sum(Max(Q)) |
+-+------------+---------+----------------+
|2| 1 | A | 23 |
+-+------------+---------+----------------+
|3| 1 | B | 11 |
+-+------------+---------+----------------+
|4| Subtotal 1 | 34 |
+-+------------+---------+----------------+
|5| 2 | C | 85 |
+-+------------+---------+----------------+
|6| 2 | D | 6 |
+-+------------+---------+----------------+
|7| Subtotal 2 | 91 |
+-+------------+--------------------------+
|8| Total 125 |
+-+---------------------------------------+
I can't do the trick of this video https://www.youtube.com/watch?v=URfAkq0_dj0 because:
I can't alter the DB.
The origin table is in the data model so I think it's the reason why I'm not able to select a custom subtotal (Not sure, correct me if I'm wrong).
Any ideas?
Oh, also I'm open to use VBA.
You can't do it in pivot. But if you can add helper column to source table, you can use following array formula to calculate MAX value in group and then use this column in pivot:
{=IF(SUM((A2=$A$2:$A2)*(B2=$B$2:$B2))=1;MAX((A2=$A$2:$A$15)*(B2=$B$2:$B$15)*($C$2:$C$15));0)}
Change semicolons to commas if needed.
Array formula after editing is confirmed by pressing ctrl + shift + enter
Assuming your pivottable looks something like this:
You can right click the subtotal line, go to "Summarize Values By" and select "Sum":
Which results in:

Excel , Multi-lookup/Match formula

I would like to use a formula in Sheet B to obtain the following transformation.
I want to vlookup stack, over, flow, super, user and the associated id's and put them into the Sheet B format. The formula would be copied horizontally across many 'Names' and then down.
Current, sheet A:
+-------------+-------+-------+
| Position_ID | Name | Value |
+-------------+-------+-------+
| 5963650267 | stack | 10 |
| 5963650267 | over | 20 |
| 5963650267 | flow | 30 |
| 5963650267 | super | 40 |
| 5963650267 | user | 50 |
| 5963650268 | stack | 90 |
| 5963650268 | over | 110 |
| 5963650268 | flow | 80 |
| 5963650268 | super | 70 |
| 5963650268 | user | 20 |
+-------------+-------+-------+
Expected, Sheet B, headers and positions ids are already pre populated:
+-------------+-------+------+------+-------+------+
| Position_ID | stack | over | flow | super | user |
+-------------+-------+------+------+-------+------+
| 5963650267 | 10 | 20 | 30 | 40 | 50 |
| 5963650268 | 90 | 110 | 80 | 70 | 20 |
+-------------+-------+------+------+-------+------+
Assuming the data in Sheet A is located at A1:C11 (adjust as required), enter this Formula Array in Sheet B at B2 then copy to all required cells (i.e. C2:F2 and B3:F3)
=INDEX('Sheet A'!$C$1:$C$11,
MATCH(CONCATENATE($A2,"|",B$1),
CONCATENATE('Sheet A'!$A$1:$A$11,"|",'Sheet A'!$B$1:$B$11),0))
Formula Array must be entered by holding down CTRL + SHIFT + ENTER
Apologies for the formatting - but if you add the vlookups to the empty shell of position_ids by name on sheet b it should give you the grid you're looking for.
Sheeta! ID&Name Position_ID Name Value
=C2&D2 1 stack 10
=C3&D3 1 over 20
=C4&D4 1 flow 30
=C5&D5 1 super 40
=C6&D6 1 user 50
=C7&D7 2 stack 90
=C8&D8 2 over 110
=C9&D9 2 flow 80
=C10&D10 2 super 70
=C11&D11 2 user 20
Sheetb! stack over flow super user
1 =VLOOKUP($A14&B$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&C$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&D$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&E$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A14&F$13,$B$2:$E$11,4,FALSE)
2 =VLOOKUP($A15&B$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&C$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&D$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&E$13,$B$2:$E$11,4,FALSE) =VLOOKUP($A15&F$13,$B$2:$E$11,4,FALSE)
Sheetb! stack over flow super user
1 10 20 30 40 50
2 90 110 80 70 20

Excel: Give scores based on range, where max = 1 and min = 10

I have following problem:
I want to give scores to a range of numbers from 1-10 for example:
| | A | B |
|---|------|----|
| 1 | 1209 | 1 |
| 2 | 401 | 7 |
| 3 | 123 | 9 |
| 4 | 49 | 10 |
| 5 | 30 | 10 |
(Not sure if B is 100% correct but roughly)
I got the B values with
=ABS(CEILING(A1;MAX($A$1:$A$32)/10)*10/MAX($A$1:$A$32)-11)
It seems to work but if I for example take numbers like
| | A | B |
|---|------|----|
| 1 | 100 | 1 |
| 2 | 90 | 2 |
| 3 | 80 | 3 |
| 4 | 70 | 4 |
| 5 | 50 | 6 |
But I want 50 to be 10.
I would like to have it scalable so I can do it with a 1-10 or 1-100 or 5-27 or whatever scale and with however many numbers in the list and whatever numbers to score from.
Thanks!
Use this formula:
=$E$1 + ROUND((MIN($A:$A)-A1)/((MAX($A:$A)-MIN($A:$A))/($E$1-$E$2)),0)
It is scalable. You put the max and min in E1 and E2.

Calculating median using two columns

I have the following columns
12 A
11 M
12 B
12 C
11 A
9 M
13 N
11 M
12 C
11 B
15 M
I want to calculate median based on only Ms. I have done by selecting ranges.
I want to use columns rather than ranges. Is there any solution? Thanks for your help
If you have 2010 or later use this formula:
=AGGREGATE(17,6,(A:A/(B:B="M")),2)
If you have 2007 or earlier, try this array formula:
=MEDIAN(IF(B:B="M",A:A))
This is an array formula and must be confirmed with Ctrl-Shift-Enter.
Though the use of full column references will slow the calculation times because it will iterate through all the rows, all 1.04 million. It is good practice to limit the references to the max data range to help offset this drain. Change the C:C to something like $C$1:$C$10000 then it will loop only 10,000 times.
Well as a VBA user I love to use VBA, other can use your skill using formulas, and is completly right if you are good on formulas. Here is my answer and I hope help you.
Imagine you have this:
+----+------------+--------------------+---------------+
| 1 | Values (A) | Criteria Range (B) | Criteria ( C) |
+----+------------+--------------------+---------------+
| 2 | 14 | B | A |
| 3 | 1 | M | |
| 4 | 15 | A | |
| 5 | 15 | E | |
| 6 | 10 | A | |
| 7 | 3 | M | |
| 8 | 11 | A | |
| 9 | 8 | M | |
| 10 | 14 | A | |
| 11 | 5 | M | |
| 12 | 9 | M | |
| 13 | 10 | M | |
| 14 | 11 | N | |
| 15 | 9 | A | |
| 16 | 2 | M | |
| 17 | 15 | M | |
| 18 | 11 | A | |
| 19 | 12 | S | |
| 20 | 9 | M | |
| 21 | 11 | A | |
| 22 | 15 | V | |
+----+------------+--------------------+---------------+
And inside the cell E2 you have this =MedianIf($A$2:$A$22,$B$2:$B$22,C2) and the result must be 11
Because in a regular module of VBA you put this function.
Function MEDIANIF(RangeIf As Range, Criteria_Range1 As Range, Criteria1 As String) As Double
Dim i
Dim Counter
Dim tmp()
Dim subCouter
subCouter = 0
For Each i In Criteria_Range1
Counter = Counter + 1
If i.Value = Criteria1 Then
subCouter = subCouter + 1
ReDim Preserve tmp(1 To subCouter)
tmp(subCouter) = RangeIf(Counter)
End If
Next i
Dim a
MEDIANIF = Application.WorksheetFunction.Median(tmp())
End Function
And the function works like this:
RangeIF = is the range with the values that you want to get the MEDIAN
Criteria_Range1 = Is the range where you have all the criteria, is the same size as RangeIF
Criteria1 = Is the criteria you use to filter the data.
How about this low-tech solution:
In Column C, formulate: =IF(B2="M",A2,"") (in rows 2-12, based on your data, and assuming row 1 contains headers)
In cell D2 (or anywhere else), formulate: =MEDIAN(C:C)

Resources