Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I create array for sequence of months between 2 dates?

I have 2 columns; start date and end date and I’d like to create the sequence of months between the two dates.

I can do this using formula and then copying the formula through the whole column

=TEXTJOIN(",",TRUE,SEQUENCE(1,MONTH(B2)-MONTH(A2)+1,MONTH(A2),1))

However, I’d like this to be created as an array. I have tried the following but it doesn’t seem to work:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

=BYROW(A2:B4,LAMBDA(a,TEXTJOIN(",",TRUE,SEQUENCE(1,MONTH(CHOOSECOLS(a,2))-MONTH(CHOOSECOLS(a,1))+1,MONTH(CHOOSECOLS(a,1)),1))))

What am I doing wrong here?

enter image description here

>Solution :

Try using the following formula:

enter image description here


=BYROW(MONTH(A2:B4),LAMBDA(α, LET(δ, INDEX(α,1), TEXTJOIN(",",,SEQUENCE(INDEX(α,2)-δ+1,,δ)))))

Edit: Using CHOOSECOLS() is also possible, only that its an array function, you would need to use the implicit intersection operator to make Excel realize that custom LAMBDA() had to be applied per row, while using INDEX() it does not require as it takes the row reference for the cols. Also using @ it needs one extra keying while the INDEX() doesn’t!

enter image description here


=BYROW(MONTH(A2:B4),LAMBDA(α,
 LET(δ,@CHOOSECOLS(α,1),TEXTJOIN(",",,
 SEQUENCE(@CHOOSECOLS(α,2)-δ+1,,δ)))))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading