How to SUMIF based on criteria from another sheet?

concavebuoyancy

New Member
Joined
Apr 21, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have where at the start of every month, I import data where it includes the prices of fruit people have bought then, example:

Buyer (Start of month)Fruit (Start of month)Price (Start of month)
Person 1Apple$2
Person 1Orange$1
Person 1Pear$1
Person 2Apple$1
Person 2Orange$1
Person 2Pear$1

In the above data, Person 1 has bought $4 of fruit, and Person 2 $3 of fruit.

Next, I want to define which of these are 'expensive fruits', in that the price of the fruit they bought is 40% >= of the total purchase cost. In this case, only Person 1 has bought an expensive fruit (Apple), as it was 50% of their total purchase cost ($2 out of $4)

In another sheet at the end of every month, I import another set of data where it again includes the prices of fruit people have bought then, example:

Buyer (End of month)Fruit (End of month)Price (End of month)
Person 1Apple$3
Person 1Orange$2
Person 2Apple$2


This is where I am stuck - Based on these 2 sheets of data, I want to sum per person, how much they spent on fruit at the end of month, divided into expensive and non-expensive fruits.

Therefore, the results would look like:

BuyerTotal Cost (Non-expensive fruit)Total Cost (Expensive fruit)
Person 1$2 (The orange)$3 (The apple, as it was >= 40% of their total purchase cost at the start of the month)
Person 2$2 (The apple. This is not an expensive fruit for them, as it only cost them $1/33% of their total purchase cost at the start of the month)0
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Welcome to the Forum!

It's not totally clear how you want to show the results. I've put them into one formula per line, but you can break this up into components if you like.

ABCDEFGHI
1Buyer (Start of month)Fruit (Start of month)Price (Start of month)
2Person 1Apple$2
3Person 1Orange$1
4Person 1Pear$1
5Person 2Apple$1
6Person 2Orange$1
7Person 2Pear$1
8ExpensiveNot expensive
9Person 1Apple,Orange$5-$0
10Person 2Apple$2Banana$1
11Person 3Orange$1-$0
12Buyer (End of month)Fruit (End of month)Price (End of month)
13Person 1Apple$3
14Person 1Orange$2
15Person 2Banana$1
16Person 2Apple$2
17Person 3Orange$1
18
Sheet1
Cell Formulas
RangeFormula
E9:E11E9=UNIQUE(A13:A17)
F9:I11F9=LET(p,A$13:A$17=E9,X,C$13:C$17>=40%*SUMIFS(C$2:C$7,A$2:A$7,A$13:A$17),CHOOSE({1,2,3,4},TEXTJOIN(",",,FILTER(B$13:B$17,p*X,"-")),SUM(FILTER(C$13:C$17,p*X,0)),TEXTJOIN(",",,FILTER(B$13:B$17,p*NOT(X),"-")),SUM(FILTER(C$13:C$17,p*NOT(X),0))))
Dynamic array formulas.
 
Upvote 0
Welcome to the Forum!

It's not totally clear how you want to show the results. I've put them into one formula per line, but you can break this up into components if you like.

ABCDEFGHI
1Buyer (Start of month)Fruit (Start of month)Price (Start of month)
2Person 1Apple$2
3Person 1Orange$1
4Person 1Pear$1
5Person 2Apple$1
6Person 2Orange$1
7Person 2Pear$1
8ExpensiveNot expensive
9Person 1Apple,Orange$5-$0
10Person 2Apple$2Banana$1
11Person 3Orange$1-$0
12Buyer (End of month)Fruit (End of month)Price (End of month)
13Person 1Apple$3
14Person 1Orange$2
15Person 2Banana$1
16Person 2Apple$2
17Person 3Orange$1
18
Sheet1
Cell Formulas
RangeFormula
E9:E11E9=UNIQUE(A13:A17)
F9:I11F9=LET(p,A$13:A$17=E9,X,C$13:C$17>=40%*SUMIFS(C$2:C$7,A$2:A$7,A$13:A$17),CHOOSE({1,2,3,4},TEXTJOIN(",",,FILTER(B$13:B$17,p*X,"-")),SUM(FILTER(C$13:C$17,p*X,0)),TEXTJOIN(",",,FILTER(B$13:B$17,p*NOT(X),"-")),SUM(FILTER(C$13:C$17,p*NOT(X),0))))
Dynamic array formulas.
Hi Stephen,

The results should look like this:

BuyerTotal Cost (Non-expensive fruit)Total Cost (Expensive fruit)
Person 1$2$3
Person 2$20

For Person 1: The $2 non-expensive fruit is the orange, which is non-expensive as it was bought for $1 originally, and not more than or equal to 40% of it's original purchase ($1/$4)
The $3 expensive fruit is the apple as it was bought for $2 originally, and not more than or equal to 40% of it's original purchase ($2/$4)

For Person 2: The $2 non-expensive fruit is the orange, which is non-expensive as it was bought for $1 originally, and not more than or equal to 40% of it's original purchase ($1/$3)
 
Upvote 0
With a helper column D, try
Book1
ABCDEFG
1Buyer (Start of month)Fruit (Start of month)Price (Start of month)Helper
2Person 1Apple2Expensive
3Person 1Orange1Not expensive
4Person 1Pear1Not expensive
5Person 2Apple1Not expensive
6Person 2Orange1Not expensive
7Person 2Pear1Not expensive
8Not expensiveExpensive
9Person 123
10Person 250
11Person 300
12Buyer (End of month)Fruit (End of month)Price (End of month)
13Person 1Apple3
14Person 1Orange2
15Person 2Banana1
16Person 2Apple2
17Person 3Orange1
Sheet5
Cell Formulas
RangeFormula
D2:D7D2=IF(C2/SUM(FILTER($C$2:$C$7,$A$2:$A$7=A2))>40%,"Expensive", "Not expensive")
E9:E11E9=UNIQUE(A13:A17)
F9:F11F9=SUM(XLOOKUP(FILTER($B$2:$B$7,($D$2:$D$7=F$8)*($A$2:$A$7=E9),""),$B$13:$B$17,$C$13:$C$17,0))
G9:G11G9=SUM(XLOOKUP(FILTER($B$2:$B$7,($D$2:$D$7=G$8)*($A$2:$A$7=E9),""),$B$13:$B$17,$C$13:$C$17,0))
Dynamic array formulas.
 
Upvote 0
Without the helper column,

Book1
ABCDEFG
1Buyer (Start of month)Fruit (Start of month)Price (Start of month)
2Person 1Apple2
3Person 1Orange1
4Person 1Pear1
5Person 2Apple1
6Person 2Orange1
7Person 2Pear1
8Not expensiveExpensive
9Person 123
10Person 250
11Person 300
12Buyer (End of month)Fruit (End of month)Price (End of month)
13Person 1Apple3
14Person 1Orange2
15Person 2Banana1
16Person 2Apple2
17Person 3Orange1
Sheet5
Cell Formulas
RangeFormula
E9:E11E9=UNIQUE(A13:A17)
F9:F11F9=SUM(XLOOKUP(FILTER($B$2:$B$7,($C$2:$C$7/BYROW($A$2:$A$7,LAMBDA(p,SUM(FILTER($C$2:$C$7,$A$2:$A$7=p))))<=40%)*($A$2:$A$7=E9),""),$B$13:$B$17,$C$13:$C$17,0))
G9:G11G9=SUM(XLOOKUP(FILTER($B$2:$B$7,($C$2:$C$7/BYROW($A$2:$A$7,LAMBDA(p,SUM(FILTER($C$2:$C$7,$A$2:$A$7=p))))>40%)*($A$2:$A$7=E9),""),$B$13:$B$17,$C$13:$C$17,0))
Dynamic array formulas.
 
Upvote 0
The results should look like this ....
... so the end of month price does not impact the expensive/not expensive question.

Without the helper column ...
I was thinking along similar lines, with a BYROW construction. But try changing your C13 to $99, say, and see that that does to your results.

Here's my take:

ABCDEFG
1Buyer (Start of month)Fruit (Start of month)Price (Start of month)
2Person 1Apple$2
3Person 1Orange$1
4Person 1Pear$1
5Person 2Apple$1
6Person 2Orange$1
7Person 2Pear$1
8ExpensiveNot expensive
9Person 1$3$2
10Person 2$0$7
11Person 3$0$1
12Buyer (End of month)Fruit (End of month)Price (End of month)
13Person 1Apple$3
14Person 1Orange$2
15Person 2Banana$1
16Person 2Apple$2
17Person 2Pear$4
18Person 3Apple$1
Sheet1
Cell Formulas
RangeFormula
E9:E11E9=UNIQUE(A13:A18)
F9:F11F9=SUMPRODUCT((A$13:A$18=E9)*C$13:C$18*BYROW(A$13:B$18,LAMBDA(r,XLOOKUP(1,(TAKE(r,,1)=A$2:A$7)*(TAKE(r,,-1)=B$2:B$7),C$2:C$7>=40%*SUMIFS(C$2:C$7,A$2:A$7,A$2:A$7),0))))
G9:G11G9=SUMIFS(C$13:C$18,A$13:A$18,E9)-F9
Dynamic array formulas.

If a person and/or fruit is not found, I have defaulted to not expensive.
 
Last edited:
Upvote 0
I was thinking along similar lines, with a BYROW construction. But try changing your C13 to $99, say, and see that that does to your results.
I didn't consider the Person in the end-of-month report. I've updated my formula and it seems to match yours but the thread is getting long. I'll let the OP to have a chance to response.
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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