Dynamic Filter by row

BrettJH

New Member
Joined
Jul 20, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm hoping someone can help me with this query.

I'm struggling to dynamically filter a table by a list of the Unique names and return the entire row from the table where the Date is the Max date.

I have a formula that filters as expected if I copy it down, however I really need this to be dynamic as the number of names will vary
=LET(dta, FILTER(Table1,(Table1[Name]=H5)),FILTER(dta,INDEX(dta,,3)=MAX(INDEX(dta,,3))))

My problems arise when I try to use it in a Lambda to dynamically process each row of the unique names.
I'm clearley not understanding something fundamental when using Byrow or Map with a Lambda to Filter rowsbased on multiple criteria.

Here's an eaxmple of the data, Table1 has these columns:

NameIDDateRate
John Doe
100​
01/01/2022​
£27​
John Doe
100​
01/06/2020​
£24​
John Doe
100​
01/01/2021​
£25​
John Doe
100​
01/01/2023​
£31​
John Doe
100​
07/10/2019​
£22​
Jane Smith
101​
19/03/2020​
£38​
Jane Smith
101​
01/01/2021​
£40​
Jane Smith
101​
01/01/2022​
£46​
Richard Roe
102​
01/05/2019​
£35​
Richard Roe
102​
01/05/2018​
£34​
Richard Roe
102​
29/08/2017​
£33​
Richard Roe
102​
01/01/2023​
£40​
Richard Roe
102​
01/01/2022​
£38​
Richard Roe
102​
01/01/2021​
£37​


The unique list of names in H5:
=UNIQUE(Table1[Name])

Unique Names
John Doe
Jane Smith
Richard Roe

and the expected result:

NameIDDateRate
John Doe
100​
01/01/2023​
31​
Jane Smith
101​
01/01/2022​
46​
Richard Roe
102​
01/01/2023​
40​


This attempt produces a #CALC! error, same if I use Byrow
=MAP(H5#,LAMBDA(r,LET(dta, FILTER(Table1,(Table1[Name]=r)),x,FILTER(dta,INDEX(dta,,3)=MAX(INDEX(dta,,3))),
x)))

This produces the correct reuslts, but all text is concatenated in a single cell in one column:
=MAP(H5#,LAMBDA(r,LET(dta, FILTER(Table1,(Table1[Name]=r)),x,FILTER(dta,INDEX(dta,,3)=MAX(INDEX(dta,,3))),
ARRAYTOTEXT(x))))

John Doe, 100, 44927, 31
Jane Smith, 101, 44562, 46
Richard Roe, 102, 44927, 40

And any attempts to Splittext produce errors.

What am I missing?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How about
Fluff.xlsm
ABCDEFGHIJ
1NameIDDateRate
2John Doe10001/01/2022£27NameIDDateRate
3John Doe10001/06/2020£24John Doe10001/01/202331
4John Doe10001/01/2021£25Jane Smith10101/01/202246
5John Doe10001/01/2023£31Richard Roe10201/01/202340
6John Doe10007/10/2019£22
7Jane Smith10119/03/2020£38
8Jane Smith10101/01/2021£40
9Jane Smith10101/01/2022£46
10Richard Roe10201/05/2019£35
11Richard Roe10201/05/2018£34
12Richard Roe10229/08/2017£33
13Richard Roe10201/01/2023£40
14Richard Roe10201/01/2022£38
15Richard Roe10201/01/2021£37
Master
Cell Formulas
RangeFormula
G2:J5G2=REDUCE(Table1[#Headers],UNIQUE(Table1[Name]),LAMBDA(x,y,VSTACK(x,FILTER(Table1,(Table1[Name]=y)*(Table1[Date]=MAXIFS(Table1[Date],Table1[Name],y))))))
Dynamic array formulas.
 
Upvote 0
Solution
Absolutely perfect!

Many thanks Fluff

I clearly need to understand the Reduce function more
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Late to the party, but offering up an alternative with Power Query for any that are interested

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    GR = Table.Group(#"Changed Type", {"Name"}, {{"Max Date", each List.Max([Date]), type nullable date}}),
    Source2 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type2" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    MQ = Table.NestedJoin(GR, {"Name","Max Date"}, #"Changed Type2", {"Name","Date"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(MQ, "Table2", {"Rate"}, {"Rate"})
in
    #"Expanded Table2"

Book5
ABCDEFGH
1NameIDDateRateNameMax DateRate
2John Doe1001/1/2022£27John Doe1/1/2023£31
3John Doe1006/1/2020£24Jane Smith1/1/2022£46
4John Doe1001/1/2021£25Richard Roe1/1/2023£40
5John Doe1001/1/2023£31
6John Doe10010/7/2019£22
7Jane Smith1013/19/2020£38
8Jane Smith1011/1/2021£40
9Jane Smith1011/1/2022£46
10Richard Roe1025/1/2019£35
11Richard Roe1025/1/2018£34
12Richard Roe1028/29/2017£33
13Richard Roe1021/1/2023£40
14Richard Roe1021/1/2022£38
15Richard Roe1021/1/2021£37
Sheet1
 
Upvote 0
Thanks Alan,

Appreciate that

That could be useful as I'm retrieving the source table via PowerQuery.
However I think I'll need to keep all the data and changes for other monthly calucations, e.g. a comp rate changes in July I will need the previous rate for May and June and the new rate moving forward until the next change. Not 100% sure yet

b
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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