How to reference cell in formula where result met condition - excel

Is there a way to write a formula for Variation so that it always relates to the lastest cell where the Variation was greater than a threshold?
In the following table the denominator of the percentage changes if the absolute value of Variation is greater than 10%. The formulas were changed manually by me.
------------------------------------------
| Row | Value | Variation| Formula |
------------------------------------------
| 1 | 1,1608 | 0,0% | A2/ A$2 - 1 |
| 2 | 1,1208 | -3,4% | A3/ A$2 - 1 |
| 3 | 1,0883 | -6,2% | A4/ A$2 - 1 |
| 4 | 1,0704 | -7,8% | A5/ A$2 - 1 |
| 5 | 1,0628 | -8,4% | A6/ A$2 - 1 |
| 6 | 1,0378 | -10,6% | A7/ A$2 - 1 | <---- Abs. Variation > 10 %
| 7 | 1,0353 | -0,2% | A8/ A$7 - 1 | <---- Change denominator
| 8 | 1,0604 | 2,2% | A9/ A$7 - 1 |
| 9 | 1,0501 | 1,2% | A10/ A$7 - 1 |
| 10 | 1,0706 | 3,2% | A11/ A$7 - 1 |
| 11 | 1,0338 | -0,4% | A12/ A$7 - 1 |
| 12 | 1,0110 | -2,6% | A13/ A$7 - 1 |
| 13 | 1,0137 | -2,3% | A14/ A$7 - 1 |
| 14 | 0,9834 | -5,2% | A15/ A$7 - 1 |
| 15 | 0,9643 | -7,1% | A16/ A$7 - 1 |
| 16 | 0,9470 | -8,7% | A17/ A$7 - 1 |
| 17 | 0,9060 | -12,7% | A18/ A$7 - 1 | <---- Abs. Variation > 10 %
| 18 | 0,9492 | 4,8% | A19/A$18 - 1 | <---- Change denominator
| 19 | 0,9397 | 3,7% | A20/A$18 - 1 |
| 20 | 0,9041 | -0,2% | A21/A$18 - 1 |
------------------------------------------
Is it possible to write a formula where the denominator changes on a given condition?
All my attempts with Array formulas, MATCH, AGGREGATE etc. went to nowhere.

Here is another way:
Place zero in E2.
In E3:
=IF(E2<-0.1,B3/B2-1,B3*(E2+1)/B2-1)
So what I'm trying to do is to work out the denominator from the previous row. So
E2=B2/denominator-1
Re-arranging you get
Denominator=B2/(E2+1)
So in the regular case you divide by this denominator, otherwise you divide by B2.

If it's possible to add another column to your data, it is very possible to do this with one IF statement. Your formula for the formula row would be:
=A2/(E1-1)
Column E formula (starting at E2) would be:
=IF(ABS(C2)>10, A2, E1)
Where E1 would be:
=A2
since that is what you have by default in your first formula.

Related

Count adyacent non-blank cells in Excel/Google Sheets

I have an Excel/Google Sheets table in which some rows contain blank cells in between non-blank cells. I would like to count from left to right. I have used the formula COUNTA(A2:F2) but it cannot achieve what I want. This is a sample of the outcome I would like to get, with the Personalized count that I am seeking to achieve and the classic COUNTA:
I think that the task is slightly different from what you describe in the question, you want to count until blank and not between not blank cells.
So I made this working example
+---+------+------+------+------+------+------+-------+
| | A | B | C | D | E | F | G |
+---+------+------+------+------+------+------+-------+
| 1 | 2021 | 2020 | 2019 | 2018 | 2017 | 2016 | Count |
| 2 | 1 | 1 | 1 | 1 | 1 | 1 | 6 |
| 3 | 1 | 1 | 1 | 1 | | | 4 |
| 4 | 1 | | 1 | 1 | 1 | 1 | 1 |
| 5 | 1 | 1 | 1 | | | 1 | 3 |
+---+------+------+------+------+------+------+-------+
where cell G2 contains the following:
=IFERROR(MATCH(1;--(A2:F2="");0)-1;COUNTA(A2:F2))
is it right for you?

Determine range for one value in a column, use to run function over same range in another

Summary
I want to have a column in my spreadsheet that does 2 things.
1) In an ordered column, it will return the range where the column contains a specified value.
2) It will run a function (i.e., =SUM(), =AVERAGE(), etc.) over that same range in a different column.
Examples
Original
| NAME | VAL | FOO |
|-------|-----|-----|
| A | 3 | |
| A | 2 | |
| A | 4 | |
| A | 3 | |
| B | 2 | |
| B | 2 | |
| B | 1 | |
| C | 6 | |
| C | 5 | |
Average
I would want to get the average of VAL for each NAME. I would want the result to be:
| NAME | VAL | FOO |
|-------|-----|-----|
| A | 3 | 3 |
| A | 2 | 3 |
| A | 4 | 3 |
| A | 3 | 3 |
| B | 2 | 1.7 |
| B | 2 | 1.7 |
| B | 1 | 1.7 |
| C | 6 | 5.5 |
| C | 5 | 5.5 |
Sum
Another example would be to get the sum of VAL for each NAME.
| NAME | VAL | FOO |
|-------|-----|-----|
| A | 3 | 12 |
| A | 2 | 12 |
| A | 4 | 12 |
| A | 3 | 12 |
| B | 2 | 5 |
| B | 2 | 5 |
| B | 1 | 5 |
| C | 6 | 11 |
| C | 5 | 11 |
Having "NAME" ordered makes it easy. If "NAME" is in A1. Enter this into C2 for the sum, then fill down:
=IF(A2=A3,C3,SUMIF($A$2:A2,A2,$B$2:B2))
Enter this into C2 for the average, then fill down:
=IF(A2=A3,C3,AVERAGEIF($A$2:A2,A2,$B$2:B2))
Note that the result in C2 won't be what you want until you fill down.
Update for MAXIF
If you don't have Excel 2016, you'll have to use an array formula (commit with ctrl+shift+enter):
=IF(A2=A3,C3,MAX(IF($A$2:A2=A2,$B$2:B2)))

How to sum a column formula

I have this Excel sheet in which I have many columns, and I need a sum formula applied to every one of them:
| | A | B | C | D | E |
| 1 | Products | Prod1 | Prod2 | Prod3 | Revenues |
| 2 | Price/u | 10 | 20 | 30 | -------- |
| 3 |Price Fixed| 5 | 10 | 2 | -------- |
| 4 |Sales | ----- | ----- | ----- | -------- |
| 5 | 2017 | 1 | 5 | 56 | ?????? |
| 6 | 2018 | 3 | 10 | 100 | ?????? |
| 7 | -------------------------------------------- |
| 8 | TOTAL | SUM() | SUM() | SUM() | -------- |
I was wondering how to calculate ?????. Indeed, it would look like:
=(B5 * B2 + B3) + (C5 * C2 + C3) + (D5 * D2 + D3), the problem is that I need to get that to Z.
Thanks!
You can use this formula:
=SUMPRODUCT(B5:Z5*B2:Z2 + B3:Z3)
SUMPRODUCT operates on arrays. It is here submitted a single array, so it just sums it up. This array is computed as:
element-wise product of the row vectors B5:Z5*B2:Z2
element-wise addition of row vector B3:Z3
You can also use an array formula and then sum the lot:
={SUM(B5:Z5*B2:Z2+B3:Z3)} not forgetting to do array formulae you use CTRL+SHIFT+ENTER

Excel dynamic range in matrix

In my excel worksheet I have a matrix like this:
+---+------------+--------+--------+--------+--------+--------+-------+
| * | A | B | C | D | E | F | Col n |
+---+------------+--------+--------+--------+--------+--------+-------+
| 1 | 01/01/2000 | -1.000 | -1.000 | -1.000 | -1.000 | -1.000 | ... |
| 2 | 01/02/2000 | | 1.200 | 500 | 500 | 500 | ... |
| 3 | 01/03/2001 | | | 1.100 | 800 | 800 | ... |
| 4 | 01/04/2000 | | | | 1.000 | 700 | ... |
| 5 | 01/05/2000 | | | | | 900 | ... |
| 6 | 01/06/2000 | | | | | | ... |
| 7 | 01/07/2000 | | | | | | ... |
+---+------------+--------+--------+--------+--------+--------+-------+
I need a formula for each column (from column 2) with a dynamic range like this:
For Column B:
=XIRR(B1:B1,A1:A1)
For Column C:
=XIRR(C1:C2,A1:A2)
For Column D:
=XIRR(D1:D3,A1:A3)
For Column E:
=XIRR(E1:E4,A1:A4)
and so on.
Is it possible?
Thanks
I think what you are after is:
=XIRR(OFFSET(B$1,0,0,COLUMN()-1),OFFSET($A$1,0,0,COLUMN()-1))
Using OFFSET we can specify the number of rows in our offset range... We can use the COLUMN() number -1 to get 1 for B, 2 for C etc. We start the offset from an unfixed cell for the values (so it moves along the columns) and a fixed one for dates (so it stays in A)
This formula can just be copied along the cells as far as necessary...

Transform values without VBA but with Index and Match

I'm trying to find a solution without macros in excel for following problem:
There is a table containing ratings of a student for different time periods.
So the rating of the student with ID=1 was 1 from January to April and 3 from Mai to June.
Two other students had a constant ranking (6 and 9) from January to June
| A | B | C |D |
---| ----|------------|------------|-------|
1 | ID | START | END |RANKING|
2 | 1 | 01.01.2014 | 30.04.2014 | 1 |
3 | 1 | 01.05.2014 | 30.06.2014 | 3 |
4 | 2 | 01.01.2014 | 30.06.2014 | 6 |
5 | 3 | 01.01.2014 | 30.06.2014 | 9 |
Next table contains IDs (y axis) and Months (x axis)
| F | G | H | I | J | K | L |
---| ----|--------|--------|--------|--------|--------|--------|
1 | ID | 201401 | 201402 | 201403 | 201404 | 201405 | 201406 |
2 | 1 | | | | | | |
3 | 2 | | | | | | |
4 | 3 | | | | | | |
And I wish to feel this second table like this:
| ID | 201401 | 201402 | 201403 | 201404 | 201405 | 201406 |
| ----|--------|--------|--------|--------|--------|--------|
| 1 | 1 | 1 | 1 | 1 | 3 | 3 |
| 2 | 6 | 6 | 6 | 6 | 6 | 6 |
| 3 | 9 | 9 | 9 | 9 | 9 | 9 |
I tried to use Index and Match, but without any good results because I haven't found a posibility to use IF (if (
Could anybody help?
You can get what you're looking for with SUMPRODUCT
Given the layout you provided, this formula should work when put in G2 and filled down and over
=SUMPRODUCT(--($A:$A=$F2),--($B:$B<=G$1),--($C:$C>G$1),$D:$D)
That looks in column A for an ID matching F2, then for every one it finds of those:
It checks the date in column B against the date in G1
It checks the date in column C against the date in G1
If all criteria match, it returns the value in Column D
This assumes you only have one entry for each period, otherwise it will sum them.
Also, you can use SUMIFS, it's a little less easy to read but I think it's slightly more efficient than SUMPRODUCT (I'm not positive, just anecdotal evidence from usage)
=SUMIFS($D:$D,$A:$A,"="&$F3,$B:$B,"<="&G$1,$C:$C,">"&G$1)
It does the exact same thing, just with different syntax.

Resources