Forum Discussion
Repeat list of items for each month in table
- Feb 11, 2025
My best guess would be the TRIMRANGE function is not yet available to you. I'm on the Current Channel for MS365 Business and just got it this month (last week).
Try the same formula but change the rng variable to just A2:R14 and it should work...
Normally a simple cross join using TOCOL-IF would suffice, but the additional criteria to repeat only some records complicates things:
=LET(
rng, TRIMRANGE(A2:R14, 2, 0),
arr, IF(ISBLANK(rng),"",rng),
hdr, TAKE(arr, 1),
bdy, DROP(arr, 1),
rId, SEQUENCE(ROWS(bdy)),
dts, TOROW(dates, 1),
inc, ISNUMBER(XMATCH(CHOOSECOLS(bdy, 4), dts)),
key, FILTER(rId, (CHOOSECOLS(bdy, 1) <> "") * NOT(inc)),
one, TOCOL(IF(dts, key),, 1),
two, FILTER(rId, inc),
top, CHOOSEROWS(bdy, one),
all, VSTACK(HSTACK(TAKE(top,, 3), TOCOL(IF(key, dts),, 1), DROP(top,, 4)), CHOOSEROWS(bdy, two)),
VSTACK(hdr, SORTBY(all, CHOOSECOLS(all, 4), 1, VSTACK(one, two), 1))
)It's a little messy but works with your sample file. Please note, it will return #CALC! if none of the records contain a matching date, or if all of the records contain matching dates (I did not generalize it to accommodate these possibilities).
Hi
Thanks for sharing this.
However when copying this into my test sheet attached here, I get the #NAME error. Looks like the range and dates is correct. Any ideas?
- djclementsFeb 11, 2025Silver Contributor
My best guess would be the TRIMRANGE function is not yet available to you. I'm on the Current Channel for MS365 Business and just got it this month (last week).
Try the same formula but change the rng variable to just A2:R14 and it should work...
- matt0020190Feb 11, 2025Brass Contributor
Works perfectly, thank you for your time and support.
Obviously as the "icing on the cake" and to make the solution perfect, this would be good to resolve in case of all records matching dates and/or none:
Please note, it will return #CALC! if none of the records contain a matching date, or if all of the records contain matching dates (I did not generalize it to accommodate these possibilities).
- djclementsFeb 12, 2025Silver Contributor
A bit cleaner, with some "icing":
=LET( rng, A2:R14, arr, IF(ISBLANK(rng),"",rng), hdr, TAKE(arr, 1), bdy, DROP(arr, 1), rId, SEQUENCE(ROWS(bdy)), mth, CHOOSECOLS(bdy, 4), dts, TOROW(dates, 1), tst, (CHOOSECOLS(bdy, 1) <> "") * ISERROR(XMATCH(mth, dts)) + (mth = dts), out, CHOOSEROWS(bdy, TOCOL(IFS(tst, rId), 2, 1)), VSTACK(hdr, HSTACK(TAKE(out,, 3), TOCOL(IFS(tst, dts), 2, 1), DROP(out,, 4))) )Cheers! 🙂