SUMIF minimum-so-far condition - excel

I am trying to set up a smart conditional summing within Excel. But the range of functions available doesn't appear to provide what I am looking for.
I have two columns of numbers. In A, I have what we'll call indentation levels. In B, I have values.
For any particular row that has child indentations, I want to use a formula in B that will calculate the sum of values in B from the next row down to the next instance of that row's A value if the corresponding value in A is the minumum it has been so far.
e.g.
row | A | B | calc'd
--------------------
1 | 0 | 9 | y
2 | 2 | 2 |
3 | 1 | 7 | y
4 | 2 | 3 |
5 | 2 | 4 |
6 | 0 | 5 | y
7 | 1 | 5 |
So, for row 1, the sum range will be rows 2 through 5. This part, I can do with an OFFSET MATCH.
The SUMIF should include row 2, as A2 is the minimum value in A2:A2.
Likewise, it should include row 3, as A3 is the minimum value in A2:A3.
But it should not include rows 4 or 5 in the sum, because their A-column values are not the minimum "so far". (These values have already been "summed up" into row 3.)
How do I create a ranged sumif with this "minimum-so-far" condition?

I found a solution to this. Not quite as clean as I wanted, but it does the trick:
Add a helper value to column C, which is the "parent row" is will sum into.
For example, C5 {=MAX(ROW($9:5)*(A$1:A4<A5))} (note: array function).
Making the final equation for B1 =SUMIF(C2:Cn,"="&ROW(),B2:Bn) (where n is the upper limit of the working range).
As written here, inserting lines messes things up, but it can all be expanded with OFFSETs for row insertability.

Related

Formula to Find if Number is between a Range in 2 Columns and then Pick 1st Column, or 2nd if Empty

There are 4 columns. 1st column has the result, 2nd column has a backup result if the 1st column is empty, the 3rd column has the low/floor value of range, and the 4th column has the high/ceiling value of range.
The Excel formula should check and see what row the search value sits in between columns 3 and 4, and then pulls column 1 if a value is found, or pulls column 2.
| 1st Column | 2nd Column|3rd Column ||3rd Column |
|------------|------------|-----------|------------|
| a |az1 | 1 | 5 |
| b |az2 | 6 | 10 |
| c |az3 | 11 | 15 |
| - |az4 | 16 | 20 |
Search Value 1: 13
Result: c
Search Value 2: 6
Result: b
Search Value 3: 19
Result: az4
Thank you in Advance for help and guidance!!
Try this formula for the all Excel versions.
In G2, enter formula :
=LOOKUP(F2,C2:C5,IF({0;0;0;1},B2:B5,A2:A5))
One way with Office 365 is:
=LET( x, G2,
low, $A$1:$B$4,
high, $C$1:$C$4,
t, INDEX(low, MATCH(x,high,1),),
INDEX( t, 1, IF(ISBLANK(INDEX(t,1,1)),2,1) ) )
You can put an IFERROR in it if you want it to give the "No Scores" result.

Excel sum if meets condition

I currently have two columns that look like this:
value | condition
50 | Y
60 | N
30 | Y
10 | Y
I cant seem to make use of IF function to get a sum of all the rows. Basically the aim here is to only sum the values if condition is Y and display the total in a cell. And if condition column is N, it will see value as 0. I want to be able to do this without the need of creating an additional column even though I understand this is easily done with a brand new column.
as Nick mentioned, you can use Sumif:
A | B
1 value | condition
2 50 | Y
3 60 | N
4 30 | Y
5 10 | Y
sumif structure:
=sumif(Range, Criteria, Sum_Range)
sumif for table above:
=sumif(B2:B5,"Y",A2:A5)
Excel formulas are not case-sensitive and there is no difference between A1:A5 and A2:A5 because the table titles are not important but start row and end row is important in both Range and Sum_Range.

Generate new table from a current table in excel

I have sample table like this:
ID | 1 | 2 | 3
-------------
1 | 0 | 1 | 0
--------------
2 | 1 | 1 | 1
Then I want to generate a new table from that table. It will take the second row (1) then compare with each column (1, 2, 3) then print value of the matrix ( 0 - 1 - 0 ). For example:
Row_ID | Column_ID | Value
--------------------------
1 | 1 | 0
--------------------------
1 | 2 | 1
--------------------------
1 | 3 | 0
--------------------------
2 | 1 | 1
--------------------------
2 | 2 | 1
--------------------------
2 | 3 | 1
I'm not sure how or where to start by using formula. Please help. Thanks,
Well. There's no single formula that's going to do the job, obviously, but we have a few options we can use. I'll assume that the new table is going to start in cell A1 of Sheet2. Adjust accordingly.
Start with manually entered headers
Row_ID | Column_ID | Value
In the first column, first row, enter a 1. In rows below, use this formula: =IF(B3<B2,A2+1,A2) This will increment the value in the first column by 1 each time the second column resets its numbering.
In the second column, first row, enter a 1. The formula we'll use for this one will need some tweaking, but the basic version is: =IF(MOD(ROW()**+1**,**3**)=0,1,B2+1)
This formula is going to essentially count up to a certain point, then reset its numbering. The point it will count to, and where it will reset, will vary depending on the amount of data you have and which row you're starting from. Replace the 3 with the number of data columns you have, and remove the **s. The +1 is needed to increase the Row() counter to the SAME NUMBER as your number of data columns. So in my example, with 3 data columns and starting on row 2, the ROW() function gives us 2, so we need to add 1 to that to get up to a total of 3. If I had 5 data columns, I would add 3 to the total. Hope that makes sense.
These two formulae should give you a set of row and column numbers. Copying the formula down will force the values to increase as needed, thus:
Row_ID | Column_ID | Value
1 | 1 |
1 | 2 |
1 | 3 |
2 | 1 |
...etc.
Finally, to bring in the values, we'll use an OFFSET formula in the Value column: =OFFSET(Sheet1!$A$1,A2,B2) That formula starts from a reference cell - A1, in this case - then moves down x number of rows and across y number of columns to return a value. X and Y are provided by the formulas we already have. Your final structure will be something like this:
Row_ID | Column_ID | Value
1 | 1 |=OFFSET(...
=IF(...|=IF(MOD(...|=OFFSET(...
I hope all that made sense. Please let me know if there's anything that doesn't, and I'll try to troubleshoot.
EDITED TO ADD:
If the Row ID is something like a key that needs to be included with each value, we can get that fairly easily. We'll include another column with a slightly modified OFFSET formula: =OFFSET(Sheet1!$A$1,A2,0)
With this version of the formula we're not changing the column as we go down, just the row when it changes. It allows the values in the first row to be repeated in every row of the table. So this is my input:
And this is my output:
Notice that the ID repeats on each line of the output for the same item.

Add page series to every second row

I have list of ID extracted from different page numbers. I wanted to add page number to every second row in Excel as shown below:
ID Number | Page Number
1 | 1
2 | 1
3 | 2
4 | 2
5 | 3
6 | 3
7 | 4
8 | 4
9 | 5
10 | 5
Is there any way to do it?
simply use in column B1:
=TRUNC((ROW()-x)/2)+1
while x is the row to start with
Or when matching with ID:
=TRUNC((A2-1)/2)+1
and then auto-fill down (in second case, A2 is the ID to that page -> order of ID's doesn't matter)
If you put values in the first 2 Page number rows then set the 3rd row to be the value of the first row, this forumla can be copied for all remaining rows
| |A|
|1|1|
|2|1|
|3|=A1+1|
|4|=A2+1|
|5|=A3+1|
Enter the following formula into cell B2 and copy down the column:
=ROUND(A2/2, 0)
where A2 is a value from the ID Number column.

Find cell name with cell contents in Excel

Say I have a table like this (the letters at the top and numbers down the side represent row/columns):
| A | B | C | D
------+----+----+----
1 | 1 | 2 | 3 | 4
2 | 5 | 6 | 7 | 8
and I want to find the cell name using the cell contents, so if the input into my function was 5, the function would return A2, as that is the position at which 5 is located.
If your data is within columns A to Z and there is only one occurrence of the particular value you are looking for, you can use the following formula:
=CHAR(SUMPRODUCT((A1:D2=5)*COLUMN(A1:D2))+64)&SUMPRODUCT((A1:D2=5)*ROW(A1:D2))
SUMPRODUCT((A1:D2=5)*COLUMN(A1:D2)) returns the column number where 5 is located.
SUMPRODUCT((A1:D2=5)*ROW(A1:D2)) returns the row number where 5 is located.
CHAR(65) gives A, so you add the column number to 64 to get the column letter.
E.g. if it is the first column, you get CHAR(1+64) which is CHAR(65) which is A.

Resources