• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

LAMBDA Assistance

SaraW

New Member
Hi experts!
I'm trying to teach myself the LAMBDA function and am struggling.
I found an awesome walk through here:
but am struggling to understand how to adjust to show
Year | Quarter | Total

Any assistance would be appreciated
 

Attachments

Last edited by a moderator:
Here's one way:

=LET(
dates,data[Date],
amounts,data[Amount],
years,YEAR(dates),
uyears,UNIQUE(years),
quarters,ROUNDUP(MONTH(dates)/3,0),
uquarters,UNIQUE(quarters),
YrQtr,IFERROR(UNIQUE(FILTER(DATE(YEAR(data[Date]), ROUNDUP(MONTH(data[Date])/3,0), 1), data[Date]<>"")), ""),
totals,BYROW(YrQtr,LAMBDA(r,SUM((years=YEAR(r))*(quarters=MONTH(r))*amounts))),
result,VSTACK({"YrQtr","Qtr","Total"},HSTACK(YEAR(YrQtr),MONTH(YrQtr),totals)),
result)

Note: If you name every part, including the final result, in LET, it's much easier to change the last argument to output any step you need to verify.
 
You may not have them yet, but there are a couple of new functions around (GROUPBY and PIVOTBY).
A single formula will generate the table

1728124486197.png

Code:
=GROUPBY(
    HSTACK(data[[#All],[Year]], data[[#All],[Quarter]]),
    data[[#All],[Amount]],
    SUM,
    3,
    2
)
or, rather more pared back
Code:
=GROUPBY(
    HSTACK(data[Year], data[Quarter]),
    data[Amount],
    SUM,
    ,
    0
)
 
Without helper columns:
Code:
=GROUPBY(YEAR(data[Date]) & " Qtr" & ROUNDUP(MONTH(data[Date])/3,0),data[Amount],SUM)
with headers:
Code:
=GROUPBY(IFERROR(YEAR(data[[#All],[Date]]) & " Qtr" & ROUNDUP(MONTH(data[[#All],[Date]])/3,0),"Year/Qtr"),data[[#All],[Amount]],SUM,3)
 
Last edited:
Back
Top