Search code examples
google-sheetsgoogle-sheets-formula

Years of seasons from dates in Google Sheets


There is an array with a body part and dates. What should a formula look like that splits it first by body parts, and then by the condition (the interval between each next date is no more than 30 days for each body part) into groups, and then outputs the years that are within that group?

For example, there are 6 groups of dates. For each group I need to output the years that are within this group (for example, if there are two years 2022 and 2023, then output 22/23, if there is only one 2021, then this year + 1, we get 21/22) enter image description here https://docs.google.com/spreadsheets/d/1Haqs37snvnBUyGO8quwfpp-nGIMOaTdgyW1S7V3rUdg/edit#gid=0


Solution

  • You may try:

    =let(Σ;{1;scan(1;B3:index(B:B;match(;0/(B:B<>"")));lambda(a;c;if(isbetween(days(c;offset(c;-1;));0;30)*(offset(c;;-1)=offset(c;-1;-1));a;a+1)))};
           map(Σ;lambda(Γ;let(Λ;text(minifs(B2:index(B:B;match(;0/(B:B<>"")));Σ;Γ);"y");Λ&"/"&Λ+1))))
    
    • group_1 output is kinda mismatching with your expected output

    enter image description here