How to increase value by X every N row?

Screenshot 2023-05-09 160941

Each month has a certain number of weeks, ex: Jan of 2023 has five weeks in total (each week’s number displayed in column C).

I want to have N number of rows in each month’s week; in the picture each month’s week has 3 rows.

What function / formula to use to calculate Year’s Week number? In other words: how to increase a value of calls in column B, by X (in this example X=1) every N (in this example N=3) rows, so the results match values in column A (so when I drag it upwards, it will auto populate newly added rows)?

Thank you for your answers :slight_smile:

WEEKNUM

https://wiki.documentfoundation.org/Documentation/Calc_Functions/WEEKNUM

No formula needed. Mark 6 rows = 2 weeks, so Calc can detect the pattern and drag upwards.

1 Like

Thank you all for answers. Most of them are way too sophisticated for a noob like me :sweat_smile: Therefore, from my perspective, the one that seemed to work the best for me so far (or the only one that I could easily follow at 11.50pm) was using =WEEKNUM function.

If I just fill in 6 rows and try to drag it, it works only if I drag it downwards, but not upwards:
Screenshot 2023-05-10 213445_2

To answer the question, but not recommending this way in your case:
You could use the remainder of the division of row-number by your block-size N like =IF(MOD(ROW(B3)-1; 3)=0; B4-1;B4)

https://wiki.documentfoundation.org/Documentation/Calc_Functions/MOD

While I use formulas like this often in conditional formatting (like your grey shading), I would not recommend it here, as adding another number of lines than 3 would alter all lines further down, maybe giving wrong results.

PS: Because of the title row, you need an offset row-1 for the calculation

1 Like

Another way:

  1. Create auxiliary cells, like
0
0
4

where X is 4, and N is 3, so first two cells are 0.

  1. Copy these cells to clipboard.

  2. Select the target range and EditPaste SpecialPaste Special... (Ctrl+Shift+V)

  3. In the dialog, select Add.
    image

This will add 0 from clipboard to first cell of selection, 0 to second, 4 to third, and start again - all in place.

2 Likes

Week numbering for years is discussed repeatedly despite the fact that there is an ISO standard for it. That’s due to objective reasons:
Months and weeks are incommensurable. Years and weeks also are. With years and months the thing only works out thanks to calendrical tricks.
I actually can’t believe that there is more than one solution for an unsolvable task.

The question used in the subject, however, has solutions. On the other hand it seems not actually clear in the context, if the solution can be based on the result you get dividing the row number by N, or if it must be based on counting repetitions (or similar).
See attached example
ask91330DoStepXafteraRunOfNequals.ods (15.3 KB)
Week numbering for months can only be done halfways reasonably if we accept that many calendaric weeks within a year will be counted more than once with different numbers as “in touch with” different months. Only in the sense of “non-empty intersection” a month can “have” more than 4 weeks, and a january like that of the year 2023 starting with a sunday (last day of its week following ISO) and ending with a tuesday will “have” 6 weeks then.

1 Like