Spreadsheet: 818800d1677061928-formula-to-grouping-data-subtotal-each-depart-and-grand-total
Sheet: Sheet1

 | COMPANY |  | DEPT |  | NAME |  |  |  | Name | DEPT | COMPANY
 | XYZ. Inc |  | EXTERNAL RELATION |  | MARIYONO |  | 1
 | ABC. Inc |  | FINANCE & ACCOUNTING |  | NAWIL |  | 1 |  |  |  |  | ABC. Inc |  |  | =LET(Comp,B3:B2000,Dept,[NAME]:D2000,Name,F3:F2000,CComp,ISNUMBER(SEARCH(L3,Comp)),CDept,ISNUMBER(SEARCH(K3,Dept)),CName,ISNUMBER(SEARCH(J3,Name)),f,UNIQUE(FILTER(HSTACK(Dept,Name,Comp),CComp*CDept*CName)),DROP(REDUCE("",UNIQUE(INDEX(f,,3)),LAMBDA(x,y,IFNA(HSTACK(x,LET(a,FILTER(f,INDEX(f,,3)=y),b,UNIQUE(INDEX(a,,1)),c,b&"|zzzz",d,MAP(SEQUENCE(ROWS(b)),LAMBDA(s,SUM(--(INDEX(a,,1)=INDEX(b,s,1))))),e,SORT(VSTACK(a,IFERROR(HSTACK(c,"",d),""))),g,VSTACK(e,HSTACK("Grand Total","",SUM(d))),h,MAP(TAKE(g,,1),LAMBDA(s,[NAME],[NAME]))
 | XYZ. Inc |  | GENERAL SERVICES |  | WAHYUDIANTO |  | 1 |  | EXTERNAL RELATION | MARIYONO | XYZ. Inc | EXTERNAL RELATION | AHMAD | ABC. Inc
 | XYZ. Inc |  | HUMAN RESOURCES |  | MUTTAQIN |  | 1 |  | EXTERNAL RELATION | NUR QAYIN | XYZ. Inc | Sub Total |  | 1
 | XYZ. Inc |  | MAINTENANCE & CONSTRUCTION |  | WILSON |  | 1 |  | Sub Total |  | 2 | FINANCE & ACCOUNTING | NAWIL | ABC. Inc
 | XYZ. Inc |  | MINE GEOLOGY & PLANNING |  | FAHRIAL |  | 1 |  | FINANCE & ACCOUNTING | [NAME] | XYZ. Inc | FINANCE & ACCOUNTING | ADI PUTRANTO | ABC. Inc
 | XYZ. Inc |  | MINE GEOLOGY & PLANNING |  | MOECHAMMAD |  | 1 |  | Sub Total |  | 1 | Sub Total |  | 2
 | XYZ. Inc |  | OPERATION |  | SELAMAT |  | 1 |  | GENERAL SERVICES | WAHYUDIANTO | XYZ. Inc | GENERAL SERVICES | ALFIAN | ABC. Inc
 | XYZ. Inc |  | QSE |  | ARAFIK |  | 1 |  | GENERAL SERVICES | WAHYUDI | XYZ. Inc | Sub Total |  | 1
 | XYZ. Inc |  | EXTERNAL RELATION |  | NUR QAYIN |  | 1 |  | Sub Total |  | 2 | HUMAN RESOURCES | SUGENG | ABC. Inc
 | XYZ. Inc |  | FINANCE & ACCOUNTING |  | [NAME] |  | 1 |  | HUMAN RESOURCES | MUTTAQIN | XYZ. Inc | Sub Total |  | 1
 | XYZ. Inc |  | GENERAL SERVICES |  | WAHYUDI |  | 1 |  | HUMAN RESOURCES | [NAME] | XYZ. Inc | MAINTENANCE & CONSTRUCTION | TRIYANTO | ABC. Inc
 | XYZ. Inc |  | HUMAN RESOURCES |  | [NAME] |  | 1 |  | Sub Total |  | 2 | Sub Total |  | 1
 | XYZ. Inc |  | MAINTENANCE & CONSTRUCTION |  | ARIS |  | 1 |  | MAINTENANCE & CONSTRUCTION | WILSON | XYZ. Inc | MINE GEOLOGY & PLANNING | [NAME] | ABC. Inc
 | XYZ. Inc |  | MINE GEOLOGY & PLANNING |  | MOHAMAD |  | 1 |  | MAINTENANCE & CONSTRUCTION | ARIS | XYZ. Inc | MINE GEOLOGY & PLANNING | IWAN | ABC. Inc
 | ABC. Inc |  | MINE GEOLOGY & PLANNING |  | [NAME] |  | 1 |  | Sub Total |  | 2 | Sub Total |  | 2
 | ABC. Inc |  | OPERATION |  | LIN SLAMET |  | 1 |  | MINE GEOLOGY & PLANNING | FAHRIAL | XYZ. Inc | OPERATION | LIN SLAMET | ABC. Inc
 | ABC. Inc |  | QSE |  | BAHAR |  | 1 |  | MINE GEOLOGY & PLANNING | MOECHAMMAD | XYZ. Inc | OPERATION | RISTANTO | ABC. Inc
 | ABC. Inc |  | EXTERNAL RELATION |  | AHMAD |  | 1 |  | MINE GEOLOGY & PLANNING | MOHAMAD | XYZ. Inc | OPERATION | ABI HAIR | ABC. Inc
 | ABC. Inc |  | FINANCE & ACCOUNTING |  | ADI PUTRANTO |  | 1 |  | Sub Total |  | 3 | Sub Total |  | 3
 | ABC. Inc |  | GENERAL SERVICES |  | ALFIAN |  | 1 |  | OPERATION | SELAMAT | XYZ. Inc | QSE | BAHAR | ABC. Inc
 | ABC. Inc |  | HUMAN RESOURCES |  | SUGENG |  | 1 |  | Sub Total |  | 1 | QSE | ANDI YANTO | ABC. Inc
 | ABC. Inc |  | MAINTENANCE & CONSTRUCTION |  | TRIYANTO |  | 1 |  | QSE | ARAFIK | XYZ. Inc | Sub Total |  | 2
 | ABC. Inc |  | MINE GEOLOGY & PLANNING |  | IWAN |  | 1 |  | Sub Total |  | 1 | Grand Total |  | 13
 | ABC. Inc |  | OPERATION |  | RISTANTO |  | 1 |  | Grand Total |  | 14
 | ABC. Inc |  | OPERATION |  | ABI HAIR |  | 1
 | ABC. Inc |  | QSE |  | ANDI YANTO |  | 1 |  | EXPECTED ANSWER / RESULT
 |  |  |  |  |  |  |  |  | XYZ. Inc |  |  | ABC. Inc
 |  |  |  |  |  |  |  |  | EXTERNAL RELATION | MARIYONO | XYZ. Inc | EXTERNAL RELATION | AHMAD | ABC. Inc
 |  |  |  |  |  |  |  |  | EXTERNAL RELATION | NUR QAYIN | XYZ. Inc | Sub Total |  | 1
 |  |  |  |  |  |  |  |  | Sub Total |  | 2 | FINANCE & ACCOUNTING | ADI PUTRANTO | ABC. Inc
 |  |  |  |  |  |  |  |  | FINANCE & ACCOUNTING | [NAME] | XYZ. Inc | FINANCE & ACCOUNTING | NAWIL | ABC. Inc
 |  |  |  |  |  |  |  |  | Sub Total |  | 1 | Sub Total |  | 2
 |  |  |  |  |  |  |  |  | GENERAL SERVICES | WAHYUDI | XYZ. Inc | GENERAL SERVICES | ALFIAN | ABC. Inc
 |  |  |  |  |  |  |  |  | GENERAL SERVICES | WAHYUDIANTO | XYZ. Inc | Sub Total |  | 1
 |  |  |  |  |  |  |  |  | Sub Total |  | 2 | HUMAN RESOURCES | SUGENG | ABC. Inc
 |  |  |  |  |  |  |  |  | HUMAN RESOURCES | [NAME] | XYZ. Inc | Sub Total |  | 1
 |  |  |  |  |  |  |  |  | HUMAN RESOURCES | MUTTAQIN | XYZ. Inc | MAINTENANCE & CONSTRUCTION | TRIYANTO | ABC. Inc
 |  |  |  |  |  |  |  |  | Sub Total |  | 2 | Sub Total |  | 1
 |  |  |  |  |  |  |  |  | MAINTENANCE & CONSTRUCTION | ARIS | XYZ. Inc | MINE GEOLOGY & PLANNING | IWAN | ABC. Inc
 |  |  |  |  |  |  |  |  | MAINTENANCE & CONSTRUCTION | WILSON | XYZ. Inc | MINE GEOLOGY & PLANNING | [NAME] | ABC. Inc
 |  |  |  |  |  |  |  |  | Sub Total |  | 2 | Sub Total |  | 2
 |  |  |  |  |  |  |  |  | MINE GEOLOGY & PLANNING | FAHRIAL | XYZ. Inc | OPERATION | RISTANTO | ABC. Inc
 |  |  |  |  |  |  |  |  | MINE GEOLOGY & PLANNING | MOHAMAD | XYZ. Inc | OPERATION | ABI HAIR | ABC. Inc
 |  |  |  |  |  |  |  |  | MINE GEOLOGY & PLANNING | MOECHAMMAD | XYZ. Inc | OPERATION | LIN SLAMET | ABC. Inc
 |  |  |  |  |  |  |  |  | Sub Total |  | 3 | Sub Total |  | 3
 |  |  |  |  |  |  |  |  | OPERATION | SELAMAT | XYZ. Inc | QSE | ANDI YANTO | ABC. Inc
 |  |  |  |  |  |  |  |  | Sub Total |  | 1 | QSE | BAHAR | ABC. Inc
 |  |  |  |  |  |  |  |  | QSE | ARAFIK | XYZ. Inc | Sub Total |  | 2
 |  |  |  |  |  |  |  |  | Sub Total |  | 1 | Grand Total |  | 13
 |  |  |  |  |  |  |  |  | Grand Total |  | 14