excelexcel-formulaindex-match

Unable to fetch data from first table into another based on more than 1 parameter


Please refer the data dump table below first.

Category Brand Transaction Amount
Category1 A 10
Category1 B 20
Category1 C 30
Category1 A 30
Category2 D 40
Category2 E 15
Category2 E
Category2 E 15

This is the an example of the table i am working on. Now there 10-11 categories and each category has 6-7 unique brands and may/may not have transaction amount in front of them.

Now i want to print the brand names with highest sum of transaction amount per category in below result table. This is easily doable by pivot by i want to achieve this using formula but unable to do so. This is the result table, where i should receive name of brands with highest sum of transaction for each category. Update: I can list the unique categories. just need the formulae to find the brand with highest sum of transaction for that specific category, thanks!

Category Brand Sum of Transaction
Category1 A 40
Category2 D 40

Solution

  • Here is one way of doing this using MS365:

    enter image description here

    =LET(
         α, A2:B9,
         δ, TAKE(α,,1),
         φ, TAKE(α,,-1),
         TAKE(SORT(UNIQUE(HSTACK(α,BYROW(α,LAMBDA(x,
         SUM((TAKE(x,,1)=δ)*(TAKE(x,,-1)=φ)*C2:C9))))),{3,1},{-1,1}),ROWS(UNIQUE(δ))))
    

    And If applicable using GROUPBY()

    enter image description here


    =LET(
         _Data, GROUPBY(A2:B9,C2:C9,SUM,,0,-3),
         _Cat, TAKE(_Data,,1),
         _Uniq, UNIQUE(_Cat),
         CHOOSEROWS(_Data, XMATCH( _Uniq, _Cat)))
    

    Or, Using the BYROW() with CHOOSEROWS() + XMATCH()

    =LET(
         _Data, A2:B9,
         _Cat, TAKE(_Data,,1),
         _Brand, TAKE(_Data,,-1),
         _Vals, BYROW(_Data,LAMBDA(x,SUM((TAKE(x,,1)=_Cat)*(TAKE(x,,-1)=_Brand)*C2:C9))),
         _Sorted, SORT(HSTACK(_Data,_Vals),{3,1},{-1,1}),
         CHOOSEROWS(_Sorted, XMATCH(UNIQUE(_Cat),TAKE(_Sorted,,1))))
    

    Also to make it more simpler, if one has listed the categories take advantage of the following:

    enter image description here


    =TAKE(UNIQUE(SORT(HSTACK($A2:$B9,SUMIFS($C2:$C9,$A2:$A9,E13,$B2:$B9,$B2:$B9)),3,-1)),1,-2)