Combining IF, SORT and UNIQUE

kumara_faith

Well-known Member
Joined
Aug 19, 2006
Messages
928
Office Version
  1. 365
Hi,

I have the following input data :

Expense Tracker.xlsx
BCDE
7DateExpenseAmount (INR)Amount (RM)
8Sunday, 30 October, 2022Biscuit20011
9Sunday, 30 October, 2022Biscuit25014
10Monday, 31 October, 2022Book1509
11Tuesday, 1 November, 2022Book1006
12Thursday, 3 November, 2022Breakfast20011
Expense Journal
Cell Formulas
RangeFormula
E8:E12E8=IF(D8="","",D8/$E$2)
Cells with Data Validation
CellAllowCriteria
B8:B356List=Date
C8:C470List=Expense1


In another table, I am trying to summarize the data based on expense type as follows (sample of correct results). The expenses are grouped and is in order of highest to lowest expense type.

Expense Tracker.xlsx
GHI
7ExpenseAmount(INR)Amount(MYR)
8Biscuit45026
9Book30014
10Breakfast20011
Expense Journal


I tried using SORT function but I could not get it right. Appreciate any help:

Expense Tracker.xlsx
GHI
15ExpenseAmount(INR)Amount(MYR)
16Biscuit25014
17Biscuit20011
18Breakfast20011
19Book1509
20Book1006
Expense Journal
Cell Formulas
RangeFormula
G16:I20G16=SORT(C8:E12,2,-1)
Dynamic array formulas.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
How about
Fluff.xlsm
BCDE
7DateExpenseAmount (INR)Amount (RM)
844864Biscuit20011
944864Biscuit25014
1044865Book1509
1144866Book1006
1244868Breakfast20011
13
14
15
16
17Biscuit45025
18Book25015
19Breakfast20011
Update
Cell Formulas
RangeFormula
B17:D19B17=LET(u,UNIQUE(C8:C12),SORT(HSTACK(u,SUMIFS(D8:D12,C8:C12,u),SUMIFS(E8:E12,C8:C12,u)),2,-1))
Dynamic array formulas.
 
Upvote 0
Hi Fluff,

Thank you for your solution and that worked. Appreciate your assistance and have a great day ahead.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Hi Fluff,

Sorry. This is my actual table in sheet 1:

Expense Tracker.xlsx
BCDE
7DateExpenseAmount (INR)Amount (RM)
8Sunday, 30 October, 2022Accommodation503
9Sunday, 30 October, 2022Biscuit503
10Monday, 31 October, 2022Biscuit513
11 
12 
13 
Expense Journal
Cell Formulas
RangeFormula
E8:E13E8=IF(D8="","",D8/$E$2)
Cells with Data Validation
CellAllowCriteria
B8:B356List=Date
C8:C470List=Expense1


And this is the formula in sheet2:

Expense Tracker.xlsx
BCD
2Expense CategoryAmount RMAmount INR
3Biscuit1016
4Accommodation503
5000
Summary
Cell Formulas
RangeFormula
B3:D5B3=LET(u,UNIQUE('Expense Journal'!C8:C190),SORT(HSTACK(u,SUMIFS('Expense Journal'!D8:D190,'Expense Journal'!C8:C190,u),SUMIFS('Expense Journal'!E8:E190,'Expense Journal'!C8:C190,u)),2,-1))
Dynamic array formulas.


Is there a reason why the last row after last data is always zero ? In this case, it will be row 5 ? Thanks
 
Upvote 0
You need to filter out the blank rows.
Excel Formula:
=LET(u,UNIQUE(FILTER('Expense Journal'!C8:C190,'Expense Journal'!C8:C190<>"")),SORT(HSTACK(u,SUMIFS('Expense Journal'!D8:D190,'Expense Journal'!C8:C190,u),SUMIFS('Expense Journal'!E8:E190,'Expense Journal'!C8:C190,u)),2,-1))
 
Upvote 0
Solution
Thank you Fluff. That worked. Appreciate your assistance and have a wonderful day ahead.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,943
Messages
6,127,826
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top