Top 3 values from a list of limited by year

michael248363

New Member
Joined
Jun 25, 2021
Messages
3
Office Version
  1. 2019
Platform
  1. Windows
I've been trying to figure out how to do this and searching here and the internet, but I can't figure it out. Maybe I'm making it harder than it needs to be and getting lost in the weeds. I'd like to do this without an array formula as I need speed with real-time calculations and every time I do array formulas it slows things down. Here is my problem recreated from a much larger, multi-sheet workbook

I can't figure out how to do the top 3 days and limit it to the year referenced in cell F1. What I get is in H2:I5. What I want is represented in H8:I11. Note that duplicate amount values cause the date to be listed as oldest first. Column C will always be sorted oldest at the top.

Book1
CDEFGHI
1DateAmount1/1/2020The Results I Get
21/6/2020$12.00Top 3 DaysDaily Amount
33/30/2020$37.007/8/2021$90.00
45/15/2020$67.005/15/2020$84.00
55/15/2020$84.005/15/2020$84.00
69/8/2020$84.00
711/11/2020$50.00The Results I Want
82/16/2021$19.00Top 3 DaysDaily Amount
96/4/2021$55.005/15/2020$84.00
107/8/2021$90.009/8/2020$84.00
119/1/2021$23.005/15/2020$67.00
1211/1/2021$84.00
Sheet1
Cell Formulas
RangeFormula
H3:H5H3=INDEX(DATE,MATCH(LARGE(AMOUNT,ROWS(H$3:H3)),AMOUNT,0))
I3:I5I3=INDEX(AMOUNT,MATCH(LARGE(AMOUNT,ROWS(I$3:I3)),AMOUNT,0))
Named Ranges
NameRefers ToCells
AMOUNT=Sheet1!$D:$DH3:I5
DATE=Sheet1!$C:$CH3:H5
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
I don't know how to edit the topic after I submit it, but the topic should be "Top 3 values from a list limited by year"
 
Upvote 0
Hi & welcome to MrExcel.
How about
+Fluff 1.xlsm
CDEFGHI
1DateAmount01/01/2020The Results I Get
206/01/202012Top 3 DaysDaily Amount
330/03/20203715/05/202084
415/05/20206708/09/202084
515/05/20208415/05/202067
608/09/202084
711/11/202050
816/02/202119
904/06/202155
1008/07/202190
1101/09/202123
1201/11/202184
13
14
List
Cell Formulas
RangeFormula
H3:H5H3=INDEX($C$2:$C$100,AGGREGATE(15,6,(ROW($C$2:$C$100)-ROW($C$2)+1)/($D$2:$D$100=I3), COUNTIFS(I$3:I3,I3)))
I3:I5I3=AGGREGATE(14,6,$D$2:$D$100/(YEAR($C$2:$C$100)=YEAR($F$1)),ROWS(I$3:I3))



The reason your formulae are slow, is that you are using entire columns which is guaranteed to slow things down.
 
Upvote 0
Solution
Here is an alternative solution using Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Amount", Int64.Type}}),
    #"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), Int64.Type),
    #"Filtered Rows" = Table.SelectRows(#"Inserted Year", each ([Year] = 2020)),
    #"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"Amount", Order.Descending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
    #"Filtered Rows1" = Table.SelectRows(#"Added Index", each ([Index] = 1 or [Index] = 2 or [Index] = 3)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Year", "Index"})
in
    #"Removed Columns"
 
Upvote 0
another PQ solution:

Book4
ABCDE
1DateAmountChoose your year:
201.06.2020122021
330.03.202137
415.05.202067DateAmount
515.05.20208407.08.202190
608.09.20218408.09.202184
711.11.20205011.01.202184
816.02.202119
906.04.202155
1007.08.202190
1109.01.202123
1211.01.202184
13
Sheet1
Cells with Data Validation
CellAllowCriteria
D2List=V1#



Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="T_Year"]}[Content]{0}[#"Choose your year:"]
in
    Source

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="T_Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Amount", type number}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Date] >= #date(T_Year, 1, 1) and [Date] <= #date(T_Year, 12, 31)),
    #"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"Amount", Order.Descending}}),
    #"Kept First Rows" = Table.FirstN(#"Sorted Rows",3)
in
    #"Kept First Rows"

also a PQ question.
I tried doing1st table more dynamic (if the header would change)
I added a step Table.columnNames, drilled it, and I was not able to reference that step marked red


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="T_Year"]}[Content]{0}[COLOR=rgb(226, 80, 65)][#"Choose your year:"][/COLOR]
in
    Source

What ever I tried I failed since Mcode did not recognized that step,
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

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