Increment a number within a formula by 2 each time - excel

As in this image:
I have the following formula in merged cellset F229:F231, which works correctly:
=OFFSET('Food Diary'!$A$2,31*(ROWS($F$18:F229)-3),)
This pulls data from another worksheet - in this case the value 73.0 is pulled (there are similar formulas in the cell range H229 to M231.
Essentially I want the -3 part at the end of above OFFSET formula to increment by two each time I copy and paste the three row set. So in the merged cellset of F232 - F234 it would be -5 and in the next one it would be -7, then -9 etc.
It's a bit of a hack but this would result in the correct data being pulled. This is not a work spreadsheet, just a personal log to record my food etc so doesn't have to be ideal.

Change -3 to +2*Row()/3 + c, where c is a modifier to ensure that your first row lines up
For example, if the first row is line 4, and you want the value to be 2:
- 2 * Row() / 3 + c
- 2 * 4 / 3 + c
- 8 / 3 + c
- 2.666 + c
c = - 1/3
- 2.666 - 1/3
- 3
- 2 * Row() / 3 - 1/3
Then, when you copy it down to Row 7:
- 2 * Row() / 3 - 1/3
- 2 * 7 / 3 - 1/3
- 14 / 3 - 1/3
- 4.666 / 3 - 1/3
- 5

Use one of the following formula for your counter starting at -3 and changing by -2 every three rows. You can either start using row A1 or you can reference your current cell and make some adjustments to the formula to achieve the same result.
=-3-2*(ROUNDUP(ROW(A1)/3,0)-1)
or
=-3-2*(ROUNDDOWN((ROW(G229)-ROW($G$229))/3,0))
both will work for generating the number you are looking for
Your final formula might look like:
=OFFSET('Food Diary'!$A$2,31*(ROWS($F$18:F229)+(-3-2*(ROUNDUP(ROW(A1)/3,0)-1))),)

Related

Excel function to return a nested SEQUENCE within COMBIN()

My current function is:
=SUM(COMBIN(5,SEQUENCE($A$1,,$A$1,-1)) * COMBIN(4,SEQUENCE($A$1,,$A$1,-1)))
where $A$1 = any potential integer. So for example, if it were 3 it would return 120 i.e.
COMBIN(5...)
COMBIN(4...)
SUM
10
4
40
10
6
60
5
4
20
120
I need to change the formula so the final number is based on a nested sequence of the input number from $A$1 so using the same example where $A$1 = 3 the result is 220 in effect summing the results of the formula with a decrementing $A$1 by 1 until it reaches 1 i.e.
COMBIN(5...)
COMBIN(4...)
SUM
10
4
40
10
6
60
5
4
20
10
6
60
5
4
20
5
4
20
220
or effectively =SUM(COMBIN(5,SEQUENCE($A$1,,$A$1,-1)) * COMBIN(4,SEQUENCE($A$1,,$A$1,-1)), COMBIN(5,SEQUENCE($A$1-1,,$A$1-1,-1)) * COMBIN(4,SEQUENCE($A$1-1,,$A$1-1,-1)), COMBIN(5,SEQUENCE($A$1-2,,$A$1-2,-1)) * COMBIN(4,SEQUENCE($A$1-2,,$A$1-2,-1)))
but because I don't know what $A$1 is, I can't write it out this way as i won't know when $A$1-x will reach 1 and therefore stop summing.
You could do it with a triangular matrix - I don't see any particular reason to count down from the starting value, you could just count up to it so the matrix would look like this:
1 -1 -1
1 2 -1
1 2 3
where the positions with -1 in aren't used.
In Excel 365 you can illustrate this with 2 steps:
=IF(SEQUENCE(1,A1)>SEQUENCE(A1,1),-1,SEQUENCE(1,A1))
to get the matrix in (say) C1 and
=SUM(IFERROR(COMBIN(4,C1#)*COMBIN(5,C1#),0))
to work through the combinations
Or use a Let formula like this to combine the two steps:
=LET(
rowSeq,SEQUENCE(A1),
colSeq,SEQUENCE(1,A1),
matrix,IF(colSeq>rowSeq,-1,colSeq),
SUM(IFERROR(COMBIN(4,matrix)*COMBIN(5,matrix),0)))
or shorter:
=LET(
rowSeq,SEQUENCE(A1),
colSeq,SEQUENCE(1,A1),
SUM(IF(colSeq>rowSeq,0,COMBIN(4,colSeq)*COMBIN(5,colSeq)))
)
Lambda Version
Define a Lambda function SumOfCombo:
=LAMBDA(N,IF(N<=0,0,SUM(COMBIN(4,SEQUENCE(N))*COMBIN(5,SEQUENCE(N)))+SumOfCombo(N-1)))
and call it with
=SumOfCombo(A1)

Repeat X in seven rows before incrementing X

Like so:
1
1
1
1
1
1
1
2
2
2
2
2
2
2
...
Something like =IF(A1=4,1,A1+1) would work if the sequence wasn't all the same value.
I believe you are looking for division:
=INT((ROW()-1)/7)
NOTE: You will have to play with the 1 and 7 in the formula above to adapt to your needs. -1 is like an offset, and 7 is the number of times for the repeat. Use -2 if the numbers should start on row 2 for example. Lastly, if you want to start with 1 instead of zero, simply add 1.
=(the previous row's value) + IF(the previous 7 rows all have the same value, 1, 0 )
Obviously(?) this will not work for the first 7 rows; the first row could be the starting value, the next 6 just a straight copy of that.

Using SUMIFS to sum all rows matching one criteria within a column matched by another criteria

I think I'm very close to what I want but I'm still getting an #N/A error -
I have some wage sheets that cross reference a labour table 'Table1' which stores the information of my employees (Pay code, Site, Contracted Hours etc). In Table1 I have columns titled 1-10 which values.
On the wage sheet I have a cell 'AM3' that will be a number between 1-10. Depending on that cell, the cell below should sum up all values in that column for all staff at that particular site.
For example - I have a wage sheet for site 'EXAMPLE SITE' which is stored in cell C2 and cell AM3 = 9.
I am trying to use the following formula to make this work:
=SUMIFS(INDEX(Table1,,MATCH(AM3,Table1[#Headers]),0),Table1[[Site]:[Site]],$C$2)
That is, I'm checking Table1, and finding the column headed with the value contained in cell AM3 (with an exact match). criteria_range1 is the Site column and criteria1 is 'EXAMPLE SITE' stored in C2.
I would expect this to sum every cell in column header 9, matching Site 'EXAMPLE SITE'. But I just get the #N/A error.
Table1:
Name - Site - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10
Tom - EXAMPLE SITE - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 10 - 20
Geoff- EXAMPLE SITE - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 9 - 18
Sarah- RANDOM SITE - 0 - 0 - 0 - 0 - 0 - 0 - 5 - 15 - 25 - 40
With that example I want the formula to return '19' as a numerical value. I feel like I'm just being dumb but no amount of googling is helping me.
MATCH seems to be having a hard time with matching table headers with numeric values. Try this:
=SUMIFS(INDEX(Table1,,MATCH(AM3,INDEX(Table1[#Headers]*1,),0)),Table1[[Site]:[Site]],$C$2)
Same problem with MATCH as earlier but alternate resolution.
=SUMIFS(INDEX(Table1[[1]:[10]],0,MATCH(TEXT(AM3, "0"),Table1[[#Headers],[1]:[10]],0)),Table1[Site],C2)

Excel | Index Match |

I require your assistance on the following:
Lets say we got 3 different groups: (A,B,C)
And we have a few value ranges within each group:
(Eg. A has 0 - 100, 101 - 200 while B has 0 - 200, 201 - 400 and C has 0 - 300, 301 - 600.)
At the end, for each group that falls under whatever range they have, they will be assigned a final number.
(Eg.
[A,95] = 0.5 / [A,101] = 1.0
[B,95] = 1.5 / [B,205] = 3.0
[C,95] = 4.5 / [C,308] = 6.0)
Currently i have my index match formula as follows:
"=INDEX(finalnumber!F2:F29,MATCH(C11&C25,Group!A2:A29&valuerange!D2:D29,0))"
I keep getting a #N/A response.
I have also created an array table as follows:
enter image description here
Group Range Final Number
A 0 - 100 0.50
A 101 - 200 1.00
B 0 - 200 1.50
B 201 - 400 3.00
C 0 - 300 4.50
C 301 - 600 6.00
Pls help! Many thanks in advance!
You can use the following (you will need to tailor to your layout). I have assumed A and 95, for example, are in separate cells as you concatenate cells in your formula to do your lookup.
=IF(AND(ISERROR(INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0))),INDEX(A:A,COUNTA(A:A)+1)=F2,G2>=1*LEFT(INDEX(B:B,COUNTA(A:A)+1),FIND("-",INDEX(B:B,COUNTA(A:A)+1))-1),G2<=1*RIGHT(INDEX(B:B,COUNTA(A:A)+1),LEN(INDEX(B:B,COUNTA(A:A)+1)) - FIND("-",INDEX(B:B,COUNTA(A:A)+1)))),INDEX(C:C,COUNTA(A:A)+1),INDEX(OFFSET(INDEX(C:C,H2),,,I2-H2+1,1),MATCH(VLOOKUP(G2,LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,TRUE),LEFT(OFFSET(INDEX(B:B,H2),,,I2-H2+1,1),FIND("-",OFFSET(INDEX(B:B,H2),,,I2-H2+1,1))-1)*1,0)))
This is entered as an array formula with Ctrl+ Shift+ Enter
Formulas in helper cells (to keep overall formula more legible):
H2 is =MATCH(F2,A:A,0) ' finds the first match for the letter e.g. A
I2 is =MAX(IF(A:A=F2,ROW(A:A)-ROW(INDEX(A:A,1,1))+1)) ' finds the last match for the letter e.g. A. This is entered with Ctrl+ Shift+ Enter i.e. an array formula.
Data layout
Example run:
Notes:
You might want to wrap the whole thing in an IFERROR( formula, "") to hide any not found error messages.
I'm unclear why you require four separate worksheets for this operation. For simplicity in demonstrating, I've put your lookup table on the same worksheet as the values to lookup.
=SUMPRODUCT(I$2:I$7, (G$2:G$7=LEFT(A2))*(--REPLACE(H$2:H$7, FIND(" - ", H$2:H$7), 9, TEXT(,))<=--MID(A2, 3, 9))*
(--REPLACE(H$2:H$7, 1, FIND(" - ", H$2:H$7)+1, TEXT(,))>=--MID(A2, 3, 9)))

increment odd or even numbers in excel/openoffice calc?

Im trying to increment in 1st column every even number by 1 and the 2nd column increment all odd numbers by 1.
what I manually have done so far:
48 4
4 49
49 4
4 50
50 4
2 51
51 2
2 52
52 2
2 53
as you can see in the 1st column every even number is incremented by 1 and in the 2nd column every odd number is incremented by 1. How can i do that automatically?
I mostly use open office calc, but I also have excel so either solution for both or one of them would be great!
You don't need code for this, it can be done using in-cell formulas.
When you want to increment all even numbers by one:
=ROUNDDOWN(A1 / 2, 0) * 2 + 1
When you want to increment all odd numbers by one:
=ROUNDUP(A1 / 2, 0) * 2
...where A1 is the name of the cell. Then just drag down the first row to extend the series into the entire column.

Resources