How to Filter data with criteria and sort it accordingly to another List rank position?

Lacan

Board Regular
Joined
Oct 5, 2016
Messages
199
Office Version
  1. 365
Platform
  1. Windows
Hi Guys, 🙌👍

Would like all the help you can give.

Quite simple, in cell B5 would like to Filter and return data headers with criteria is to search both Bricks simultaneous 301 Lx - NEW YORK (Venteira) and 302 Lx - NEW YORK (Alfragide, ÁLivres) which sales has to be >0.
After that steep sort it accordingly with rank brick position in ascending order.
All of that in one unique formula.
Feel free if need more additional explanation.
Thank you very much!! 👍👍💪💪🍻

Fórmula Principal para o Ficheiro VDF.xlsm
ABCDEFGHIJKLMNOPQ
1
2BRICKNAMECODESALES
3FILTERED CRITERIASORT CRITERIA299 Lx - NEW YORK (MÁgua - Sul)NEW YORKD076999
4BRICKNAMECODESALESBRICKSALES >0BRICK RANKORDER299 Lx - NEW YORK (MÁgua - Sul)CENTRAL - NEW YORKD051503
5301 Lx - NEW YORK (Venteira)299 Lx - NEW YORK (MÁgua - Sul)6299 Lx - NEW YORK (MÁgua - Sul)DIAS & BRITOD040
6302 Lx - NEW YORK (Alfragide, ÁLivres)300 Lx - NEW YORK (MÁgua - Norte)2299 Lx - NEW YORK (MÁgua - Sul)CARLOS - NEW YORKD030
7301 Lx - NEW YORK (Venteira)4299 Lx - NEW YORK (MÁgua - Sul)DE CARENQUE D010
8302 Lx - NEW YORK (Alfragide, ÁLivres)3300 Lx - NEW YORK (MÁgua - Norte)ROMEIROD06371
9308 Lx - LONDON (Benfica - Sul)5300 Lx - NEW YORK (MÁgua - Norte)NUNESD033968
10310 Lx - LONDON (Estrela)1300 Lx - NEW YORK (MÁgua - Norte)SOARES CORREIAD030
11300 Lx - NEW YORK (MÁgua - Norte)DO GUIZOD020
12300 Lx - NEW YORK (MÁgua - Norte)TANARA NEW YORKD0112012
13301 Lx - NEW YORK (Venteira)CONTINENTE NEW YORKD080
14301 Lx - NEW YORK (Venteira)CLABELD070
15301 Lx - NEW YORK (Venteira)HELENICAD071641
16301 Lx - NEW YORK (Venteira)CAMPOSD0411955
17308 Lx - LONDON (Benfica - Sul)CAVACAD040
18308 Lx - LONDON (Benfica - Sul)DO BORELD040
19308 Lx - LONDON (Benfica - Sul)IGREJAD020
20301 Lx - NEW YORK (Venteira)JARDIM - NEW YORKD020
21301 Lx - NEW YORK (Venteira)MELO - NEW YORKD020
22301 Lx - NEW YORK (Venteira)SAO JORGED020
23301 Lx - NEW YORK (Venteira)CONFIANCA - NEW YORKD010
24302 Lx - NEW YORK (Alfragide, ÁLivres)DAMAIAD09131
25302 Lx - NEW YORK (Alfragide, ÁLivres)DA QUINTA GRANDED071842
26302 Lx - NEW YORK (Alfragide, ÁLivres)HELENOD07530
27302 Lx - NEW YORK (Alfragide, ÁLivres)REMEDIOSD070
28310 Lx - LONDON (Estrela)GASPAR POTED043216
29310 Lx - LONDON (Estrela)D JOAO VD030
30302 Lx - NEW YORK (Alfragide, ÁLivres)VAZ MARTINSD03700
31302 Lx - NEW YORK (Alfragide, ÁLivres)CONFIANCA - DAMAIAD020
32
33
34
20-07-2024
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Something like this?

Excel Formula:
=LET(
filter,FILTER(M3:P31,((M3:M31=G5)+(M3:M31=G6))*(P3:P31>0)),
sort,XLOOKUP(CHOOSECOLS(filter,1),J5:J10,K5:K10),
SORTBY(filter,sort))
 
Upvote 0
Or an alternative with Power Query
Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    T2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    MQ = Table.NestedJoin(T1, {"BRICK"}, T2, {"BRICK"}, "T3", JoinKind.LeftOuter),
    ExpandedT3 = Table.ExpandTableColumn(MQ, "T3", {"SALES"}, {"SALES"}),
    FilteredRows = Table.SelectRows(ExpandedT3, each [SALES] > 0),
    CountRows = Table.Group(FilteredRows, {"BRICK"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    Sort = Table.Sort(CountRows,{{"BRICK", Order.Ascending}})
in
    Sort
 
Upvote 0
Something like this?

Excel Formula:
=LET(
filter,FILTER(M3:P31,((M3:M31=G5)+(M3:M31=G6))*(P3:P31>0)),
sort,XLOOKUP(CHOOSECOLS(filter,1),J5:J10,K5:K10),
SORTBY(filter,sort))
Dear @hagia_sofia

Fits like a glove - Perfect!!!
If you don´t mind keeping the same Formula can you please update and add 2 new Sorts: First for the "Sales" (descending order) and then for "Code"(descending order)?
Thank you very much!!! 👌👍👍
 
Upvote 0
Or an alternative with Power Query
Power Query:
let
    T1 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    T2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    MQ = Table.NestedJoin(T1, {"BRICK"}, T2, {"BRICK"}, "T3", JoinKind.LeftOuter),
    ExpandedT3 = Table.ExpandTableColumn(MQ, "T3", {"SALES"}, {"SALES"}),
    FilteredRows = Table.SelectRows(ExpandedT3, each [SALES] > 0),
    CountRows = Table.Group(FilteredRows, {"BRICK"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    Sort = Table.Sort(CountRows,{{"BRICK", Order.Ascending}})
in
    Sort
Dear @alansidman

Thank you very much for the help.💪💪👍
 
Upvote 0
Dear @hagia_sofia

Fits like a glove - Perfect!!!
If you don´t mind keeping the same Formula can you please update and add 2 new Sorts: First for the "Sales" (descending order) and then for "Code"(descending order)?
Thank you very much!!! 👌👍👍

Like this?

Excel Formula:
=LET(
filter,FILTER(M3:P31,((M3:M31=G5)+(M3:M31=G6))*(P3:P31>0)),
sort,XLOOKUP(CHOOSECOLS(filter,1),J5:J10,K5:K10),
SORTBY(filter,sort,1,CHOOSECOLS(filter,4),-1,CHOOSECOLS(filter,3),-1))
 
Upvote 0
Solution
Dear @hagia_sofia

Brilliant!!! 👌👍👍
Thank you very much!!!

Dear @hagia_sofia

Just one last single update, after filter data would like to return shorten text data only in column "BRICK".
To give an example, instead of they return like:

299 Lx - NEW YORK (MÁgua - Sul)
302 Lx - NEW YORK (Alfragide, ÁLivres)

Prefer much more like this:

299 (MÁgua - Sul)
302 (Alfragide, ÁLivres)

Can you please update it in your last Formula?

Think Im done now!!!
Thank you very much!!!! 👌👍👍
 
Upvote 0
Test this - it is even longer than before:

Excel Formula:
=LET(
brick,O3:O31,
filter,FILTER(O3:R31,((brick=G5)+(brick=G6))*(R3:R31>0)),
sort,XLOOKUP(CHOOSECOLS(filter,1),J5:J10,K5:K10),
array,SORTBY(filter,sort,1,CHOOSECOLS(filter,4),-1,CHOOSECOLS(filter,3),-1),
brick_alt,TEXTBEFORE(brick," ",1)&" "&MID(brick,FIND("(",brick),LEN(brick)-FIND("(",brick)+1),
replace,XLOOKUP(CHOOSECOLS(array,1),brick,brick_alt),
HSTACK(replace,CHOOSECOLS(array,2,3,4)))
 
Upvote 0

Forum statistics

Threads
1,221,467
Messages
6,160,018
Members
451,611
Latest member
PattiButche

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