Last occurence if two criteria match

ausswe

New Member
Joined
Feb 19, 2013
Messages
38
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have tried various formulas that I've found online but keep getting error messages.
I have a set of data that contains the following columns: ID (column A), Activity (column B), Resource (column C) where one ID can have multiple rows with different activities and resources.

I have created a unique list of IDs (column D) and am trying to figure out how to get the last occurence of Resource if ID (col A) matches the value in D1:D2000 AND the activity (col B) equals a specific value.

Anyone that might have any suggestions?
Thanks in advance
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
would something like this do the trick ?

Book1
ABCD
1jogging
2IDActivityResource
31runningresource 11
41walkingresource 23
52runningresource 32
63sittingresource 45
74drivingresource 54
84walkingresource 63
95joggingresource 75
10
11
125joggingresource 7
Sheet1
Cell Formulas
RangeFormula
A12:C12A12=FILTER(A3:C9,(B3:B9=B1)*(A3:A9 = D3:D9),"no results")
Dynamic array formulas.
 
Upvote 0
whats in resource - without a view of the data , may be difficult , is this text or number
BUT a FILTER may work with a TAKE ( -1)

Column D? whats in D the unique IDs
something like
=TAKE(FILTER($A$2:$C$17,($B$2:$B$17=$F$2)*($A$2:$A$17=E3)),-1)

Book1
ABCDEFGH
1ID (column A) Activity (column B) Resource (column C)
2AAct-1Res-1Act-12
3AAct-2Res-2AAAct-12Res-7
4AAct-3Res-3BBAct-12Res-15
5AAct-4Res-4
6AAct-12Res-5
7AAct-12Res-6
8AAct-12Res-7
9AAct-8Res-8
10AAct-9Res-9
11BAct-10Res-10
12BAct-11Res-11
13BAct-12Res-12
14BAct-13Res-13
15BAct-12Res-14
16BAct-12Res-15
17BAct-16Res-16
18
Sheet1
Cell Formulas
RangeFormula
E3:E4E3=UNIQUE(A2:A17)
F3:H4F3=TAKE(FILTER($A$2:$C$17,($B$2:$B$17=$F$2)*($A$2:$A$17=E3)),-1)
Dynamic array formulas.



herefore -

A good sample workbook has just 10-20 rows of representative data that has been desensitised. The sample layout accurately matches that of your real data. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.

This will possibly enable a quicker and more accurate solution for you.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC

then put the sample spreadsheet onto a share

I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed

Make sure you set any share or google to share to everyone

if you have any issues with XL2BB, then the "About this Board" is the forum to ask questions about XL2BB
 
Upvote 0
sorry, might need to add this to it for last occurence:

Excel Formula:
=TAKE(FILTER(A3:C9,(B3:B9=B1)*(A3:A9 = D3:D9),"no results"),-1)

oops... this from my original post.

Rob
 
Upvote 0
Try this:

Book1
ABCDEF
1
2IDActivity Resource
3A1On1A188
4A2Off2A21010
5A3On3A333
6A4Off4A4 
7A2On5
8A2On6
9A2Off7
10A1On8
11A4Off9
12A2On10
Sheet1
Cell Formulas
RangeFormula
D3:D6D3=UNIQUE(A3:A12)
E3:E6E3=XLOOKUP(D3#&"/On",$A$3:$A$12&"/"&$B$3:$B$12,$C$3:$C$12,"",0,-1)
F3:F6F3=IFERROR(LOOKUP(2,1/($A$3:$A$12=D3)/($B$3:$B$12="On"),$C$3:$C$12),"")
Dynamic array formulas.
 
Upvote 0
sorry, might need to add this to it for last occurence:

Excel Formula:
=TAKE(FILTER(A3:C9,(B3:B9=B1)*(A3:A9 = D3:D9),"no results"),-1)

oops... this from my original post.

Rob
Thanks Rob,
Unfortunately I'm not allowed to install the extension on this computer, but I created an example spreadsheet and uploaded it to OneDrive:
LastOccurenceIfMatchTwoCriteria.xlsx
 
Upvote 0
you are using

=TAKE(FILTER($C$3:$C$8050,($A$3:$C$8050=$G$2)*($A$3:$A$8050=F3)),-1)
a range
should that be

=TAKE(FILTER($C$3:$C$8050,($B$3:$B$8050=$G$2)*($A$3:$A$8050=F3)),-1)

Small sample

LastOccurenceIfMatchTwoCriteria.xlsx
ABCDEFGH
1DATASETFILTERED RESULTLast resource if activity:Last resource if activity:
2IDActivityResourceStart dateUNIQUE-IDMovemServ
30B0205MovemTJ Fro14/1/240B0205#VALUE!STJ MDT
40B0205MovemTJ Fro14/1/240FC208
50B0205MovemTJ Fro14/1/2400620E
60B0205MovemTJ Fro14/1/240D2201
70B0205MovemTJ Fro14/1/2409620B
80B0205MovemTJ Fro14/1/2408020E
90B0205MovemTJ Fro14/1/2407320D
100B0205MovemTJ Fro14/1/240E0200
110B0205MovemTJ Fro14/1/240A720E
120B0205MovemTJ Fro14/1/24091205
130B0205ServSTJ MDT4/1/240CA202
140B0205ServSTJ MDT4/1/240D0201
150B0205ServSTJ MDT4/1/240E6208
160B0205ServSTJ MDT4/1/24066209
Sheet2
Cell Formulas
RangeFormula
F3:F1400F3=DROP(UNIQUE(A:A),2)
G3G3=TAKE(FILTER($C$3:$C$8050,($A$3:$C$8050=$G$2)*($A$3:$A$8050=F3)),-1)
H3H3=TAKE(FILTER($C$3:$C$8050,($B$3:$B$8050=$H$2)*($A$3:$A$8050=F3)),-1)
Dynamic array formulas.
Named Ranges
NameRefers ToCells
_FilterDatabase=Sheet2!$A$2:$H$8050F3
 
Upvote 0
Solution
you are using

=TAKE(FILTER($C$3:$C$8050,($A$3:$C$8050=$G$2)*($A$3:$A$8050=F3)),-1)
a range
should that be

=TAKE(FILTER($C$3:$C$8050,($B$3:$B$8050=$G$2)*($A$3:$A$8050=F3)),-1)

Small sample
Thanks Etaf - you are correct, now it seems to work!
 
Upvote 0

Forum statistics

Threads
1,217,382
Messages
6,136,234
Members
450,000
Latest member
jgp19

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