I have this formula:
=LET(a;FRUITS!A2:INDEX(FRUITS!B:B;LOOKUP(2;1/(FRUITS!A:A<>"");ROW(FRUITS!B:B)));
aa;INDEX(a;;1);
ab;INDEX(a;;2);
u;UNIQUE(INDEX(a;;2));
c;COUNTIF(ab;u);
d;COUNTIFS(ab;u;
aa;">="&TODAY()
-VLOOKUP(SUBSTITUTE(D2;" ";"");
{"24HOURS"\0;"2DAYS"\1;"3DAYS"\4;"7DAYS"\7;"2WEEKS"\14;"1MONTH"\30;"3MONTHS"\90;"6MONTHS"\180;"1YEAR"\365;"2YEARS"\730;"3YEARS"\1095;"TOTAL"\999999};
2;0));
SORT(CHOOSE({1\2\3};u;c;d);{2\1\1};{-1\1\1}))
This is in one sheet where the formula is:
This is the other sheet containing the table with the raw data:
It is not counting by period in my real work file. I don't know why. Probably something to do with date formats? Now when I made this dummy file, I just changed names, and now it is working. The names in the real file are of people instead of fruits, like: "Doe, John", "Jane, Mary" etc. Could this be the problem and not the date format?
Also, I would like to have only 2 columns: one with the names of the unique items, and the 2nd with count "By Period". If I want the total count, I will just choose from the validation menu. The name's column on the left should be sorted by descending order according to the count by period.
Here is a file:
https://1drv.ms/x/s!AhJ6NsWJczYBhSjKQVMab8WlYINT?e=akPt6d
EDIT:
The expected result is below. The count would change according to the period chosen above. In this case by month: