Filter specific rows from a table

vladimiratanasiu

Active Member
Joined
Dec 17, 2010
Messages
359
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello!

I have a larger .csv table, with quotes of cereals. The data are structured based on the weeks of a year (week 51, 50, 49, 48 etc./2023), type of cereals (wheat/feed barely) and regions (south, west, east, FOB Constanta). As it's seen, the reference period is common for the two products (rows 1, 12, 23, 34 etc), but the regions are repeated separately, for each type of cereals. I need a solution, to filter and show only the rows with the period of reference (rows 1, 12, 23, 34 etc.), and the specific values for the WHEAT from the SOUTH region ( rows 5, 16, 27, 38 etc.).
Thank you in advance!
Cotatii-Cereale-2023-1(1).csv
ABC
1<strong><em>WEEK 51/2023 (WEEK 21 - 27 DECEMBER 2023)</em></strong>#colspan##colspan#
2<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
3WEST8853.39
4EAST-0
5SOUTH760-18.1
6FOB CONSTANTA11011.47
7<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
8WEST-0
9EAST-0
10SOUTH-0
11FOB CONSTANTA-0
12<strong><em>WEEK 50/2023 (WEEK 14 - 20 DECEMBER 2023)</em></strong>#colspan##colspan#
13<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
14WEST8564.01
15EAST10183.98
16SOUTH9282.09
17FOB CONSTANTA1085-4.66
18<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
19WEST650-11.2
20EAST8330.12
21SOUTH80012.2
22FOB CONSTANTA-0
23<strong><em>WEEK 49/2023 (WEEK 07 - 13 DECEMBER 2023)</em></strong>#colspan##colspan#
24<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
25WEST823-10.05
26EAST979-2.59
27SOUTH9090.22
28FOB CONSTANTA11380.09
29<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
30WEST7324.57
31EAST8322.09
32SOUTH713-8.59
33FOB CONSTANTA-0
34<strong><em>WEEK 48/2023 (WEEK 30 NOVEMBER - 06 DECEMBER 2023)</em></strong>#colspan##colspan#
35<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
36WEST9150.55
37EAST10052.24
38SOUTH9071.23
39FOB CONSTANTA1137-0.52
40<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
41WEST-0
42EAST815-5.89
43SOUTH780-8.45
44FOB CONSTANTA-0
Cotatii-Cereale-2023-1(1)
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hello, provided that the data has the same structure as depicted above you could test the following:

Excel Formula:
=LET(
a,A1:A44,
b,B1:B44,
c,A1:C44,
d,TOCOL(IF(SEQUENCE(,8),FILTER(a,ISNUMBER(SEARCH("WEEK",a))))),
e,TOCOL(IF(SEQUENCE(,4),FILTER(b,ISNUMBER(SEARCH("RON/tone",b))))),
f,FILTER(c,NOT(ISNUMBER(SEARCH("<strong>",a)))),
g,HSTACK(d,e,f),
FILTER(g,(CHOOSECOLS(g,2)="<strong><em>WHEAT (RON/tone)</em></strong>")*(CHOOSECOLS(g,3)="SOUTH")))
 
Upvote 0
Hello, provided that the data has the same structure as depicted above you could test the following:

Excel Formula:
=LET(
a,A1:A44,
b,B1:B44,
c,A1:C44,
d,TOCOL(IF(SEQUENCE(,8),FILTER(a,ISNUMBER(SEARCH("WEEK",a))))),
e,TOCOL(IF(SEQUENCE(,4),FILTER(b,ISNUMBER(SEARCH("RON/tone",b))))),
f,FILTER(c,NOT(ISNUMBER(SEARCH("<strong>",a)))),
g,HSTACK(d,e,f),
FILTER(g,(CHOOSECOLS(g,2)="<strong><em>WHEAT (RON/tone)</em></strong>")*(CHOOSECOLS(g,3)="SOUTH")))
Thank you for the answer. I applied your formula, but it generates only partially my necessary results. I need to be included the whole content from the marked rows with South region (e.g A5:C5), and also the rows with the periods (e.g. A1:C1). I attach the filtered content from the above table, exactly as I need it to be shown. Could you adjust / change your formula, for it to lead to the necessary data? Thank you!

Book1
ABC
1<strong><em>WEEK 51/2023 (WEEK 21 - 27 DECEMBER 2023)</em></strong>#colspan##colspan#
5SOUTH760-18.1
12<strong><em>WEEK 50/2023 (WEEK 14 - 20 DECEMBER 2023)</em></strong>#colspan##colspan#
16SOUTH9282.09
23<strong><em>WEEK 49/2023 (WEEK 07 - 13 DECEMBER 2023)</em></strong>#colspan##colspan#
27SOUTH9090.22
34<strong><em>WEEK 48/2023 (WEEK 30 NOVEMBER - 06 DECEMBER 2023)</em></strong>#colspan##colspan#
38SOUTH9071.23
Sheet1
 
Upvote 0
Many thanks for the feedback. If the data follow the same pattern as shown above would this work then:

Excel Formula:
=LET(
a,A1:C44,
b,ROWS(a),
FILTER(a,(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,1,11),SEQUENCE(4,,1,11))))+(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,5,11),SEQUENCE(4,,5,11))))))
 
Upvote 0
Another couple of possibilities you could try:

Excel Formula:
=FILTER(A1:C1000,(B1:B1000="#colspan#")+((A1:A1000="SOUTH")*ISNUMBER(SEARCH("WHEAT",SCAN("",B1:B1000,LAMBDA(a,v,IF(LEFT(v)="<",v,a)))))))
-OR-
Excel Formula:
=LET(rng,A1:C44,seq,SEQUENCE(ROWS(rng)/11,,,11),CHOOSEROWS(rng,TOCOL(HSTACK(seq,seq+4))))

Adjust the range references as needed.
 
Upvote 0
Solution
Another option:
Excel Formula:
=CHOOSEROWS(A1:C44,1,SCAN(1,4+3*MOD(SEQUENCE(ROWS(A1:A44)/6)-1,2),SUM))
 
Upvote 0
Thank
Many thanks for the feedback. If the data follow the same pattern as shown above would this work then:

Excel Formula:
=LET(
a,A1:C44,
b,ROWS(a),
FILTER(a,(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,1,11),SEQUENCE(4,,1,11))))+(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,5,11),SEQUENCE(4,,5,11))))))

Many thanks for the feedback. If the data follow the same pattern as shown above would this work then:

Excel Formula:
=LET(
a,A1:C44,
b,ROWS(a),
FILTER(a,(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,1,11),SEQUENCE(4,,1,11))))+(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,5,11),SEQUENCE(4,,5,11))))))
Thank you, hagia_sofia, for your effort ! Unfortunately, your formula can cover only the weeks 48-51, mentioned in the posted table. If I try to extend it to the weeks 1-47/2023, it can't generate results for the rest of them.
Cotatii-Cereale-2022.csv
ABCDEF
1<strong><em>WEEK 51/2023 (WEEK 21 - 27 DECEMBER 2023)</em></strong>#colspan##colspan#<strong><em>WEEK 51/2023 (WEEK 21 - 27 DECEMBER 2023)</em></strong>#colspan##colspan#
2<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>SOUTH760-18.1
3WEST8853.39<strong><em>WEEK 50/2023 (WEEK 14 - 20 DECEMBER 2023)</em></strong>#colspan##colspan#
4EAST-0SOUTH9282.09
5SOUTH760-18.1<strong><em>WEEK 49/2023 (WEEK 07 - 13 DECEMBER 2023)</em></strong>#colspan##colspan#
6FOB CONSTANTA11011.47SOUTH9090.22
7<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong><strong><em>WEEK 48/2023 (WEEK 30 NOVEMBER - 06 DECEMBER 2023)</em></strong>#colspan##colspan#
8WEST-0SOUTH9071.23
9EAST-0
10SOUTH-0
11FOB CONSTANTA-0
12<strong><em>WEEK 50/2023 (WEEK 14 - 20 DECEMBER 2023)</em></strong>#colspan##colspan#
13<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
14WEST8564.01
15EAST10183.98
16SOUTH9282.09
17FOB CONSTANTA1085-4.66
18<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
19WEST650-11.2
20EAST8330.12
21SOUTH80012.2
22FOB CONSTANTA-0
23<strong><em>WEEK 49/2023 (WEEK 07 - 13 DECEMBER 2023)</em></strong>#colspan##colspan#
24<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
25WEST823-10.05
26EAST979-2.59
27SOUTH9090.22
28FOB CONSTANTA11380.09
29<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
30WEST7324.57
31EAST8322.09
32SOUTH713-8.59
33FOB CONSTANTA-0
34<strong><em>WEEK 48/2023 (WEEK 30 NOVEMBER - 06 DECEMBER 2023)</em></strong>#colspan##colspan#
35<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
36WEST9150.55
37EAST10052.24
38SOUTH9071.23
39FOB CONSTANTA1137-0.52
40<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
41WEST-0
42EAST815-5.89
43SOUTH780-8.45
44FOB CONSTANTA-0
45<strong><em>WEEK 47/2023 (WEEK 23 NOVEMBER - 29 NOVEMBER 2023)</em></strong>#colspan##colspan#
46<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>WHEAT (RON/tone)</em></strong><strong><em>Var. %</em></strong>
47WEST1415-11.4
48EAST1478-2.64
49SOUTH15080.07
50FOB CONSTANTA-0
51<strong><em>DELIVERY AREA/PRODUCT</em></strong><strong><em>FEED BARELY (RON/tone)</em></strong><strong><em>Var. %</em></strong>
52WEST-0
53EAST1324-4.06
54SOUTH13000
55FOB CONSTANTA-0
Sheet2
Cell Formulas
RangeFormula
D1:F8D1=LET( a,A1:C55, b,ROWS(a), FILTER(a,(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,1,11),SEQUENCE(4,,1,11))))+(ISNUMBER(XLOOKUP(SEQUENCE(b),SEQUENCE(4,,5,11),SEQUENCE(4,,5,11))))))
Dynamic array formulas.
 
Upvote 0
Another option:
Excel Formula:
=CHOOSEROWS(A1:C44,1,SCAN(1,4+3*MOD(SEQUENCE(ROWS(A1:A44)/6)-1,2),SUM))
Thank you, Cubist , for your solution! It works almost perfectly for the whole year 2023. Anyway, it strangely works until to the week 5 only. The weeks 1-4 are not included in the final results.
 
Upvote 0
Another couple of possibilities you could try:

Excel Formula:
=FILTER(A1:C1000,(B1:B1000="#colspan#")+((A1:A1000="SOUTH")*ISNUMBER(SEARCH("WHEAT",SCAN("",B1:B1000,LAMBDA(a,v,IF(LEFT(v)="<",v,a)))))))
-OR-
Excel Formula:
=LET(rng,A1:C44,seq,SEQUENCE(ROWS(rng)/11,,,11),CHOOSEROWS(rng,TOCOL(HSTACK(seq,seq+4))))

Adjust the range references as needed.
Thank you, djclements ! Your two formulas work perfectly!
 
Upvote 0

Forum statistics

Threads
1,225,346
Messages
6,184,425
Members
453,231
Latest member
HerGP

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