replace filter

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,065
Office Version
  1. 365
Platform
  1. Windows
i have inherited a report that uses FILTER to transform the raw data input into a meaningful report. The original report used set ranges for each filter formula and these had to be expanded each time new data was added. to get around this, i changed all the ranges to dynamic named ranges (using indirect). the file is ballooning in size each month as its updated. Before FILTER, i would have run formulas adjacent to a pivot table (getting unique data from a list of multiples). This would probably still result in a large file but would it be as large?? any ideas on better method folks?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi ajm,

Based on my experience, filters and formulas end-up eating your memory in large file. If you use Excel as à huge database, I would recommand thinking about vba. We could take a look if you have some example or dummy data if there is something to do before going towards vba.

Bests regards,

Vincent
 
Upvote 0
Have you looked at Power Query ? It is currently considered to be the go to method for transforming the raw data.
 
Upvote 0
If you want to stick with FILTERs ...
If you do not already have the TRIMRANGE function you might choose to wait a bit longer before deciding to change as this function allows for expanding ranges.
There is also a new "Trim ref" notation that allows for the abbreviation of the TRIMRANGE function, at least in some circumstances.

In the mini sheet below I have a standard FILTER function in G2, one using whole column references in G12, one using TRIMRANGE M2 and one using the trim ref abbreviations in M12. As you can see, they all produce the same result.

ajm.xlsm
ABCDEFGHIJKLMNOPQ
1Data1Data2Data3Data4Data5
2UNEDICCGRBCCGRB
3TNHNFCCXIBCCXIB
4CCGRBCOHSBCOHSB
5FEOUI
6PENOU
7AYXLJ
8BYHJU
9CCXIB
10YGCVN
11MRGYP
12KFTKSCCGRBCCGRB
13GXEAXCCXIBCCXIB
14MAWLGCOHSBCOHSB
15BCWPI
16SHVFJ
17COHSB
18KWOUA
19COIED
20YUGTR
21
Sheet1
Cell Formulas
RangeFormula
G2:K4G2=FILTER(A2:E20,(A2:A20="C")*(E2:E20="B"))
M2:Q4M2=FILTER(TRIMRANGE(A:E,2),(TRIMRANGE(A:A,2)="C")*(TRIMRANGE(E:E,2)="B"))
G12:K14G12=FILTER(A:E,(A:A="C")*(E:E="B"))
M12:Q14M12=FILTER(A:.E,(A:.A="C")*(E:.E="B"))
Dynamic array formulas.


Now, if I add some more data the G2 formula would need amendment as you described, but the others all produce the correct results for the expanded data. The difference is that the two formulas in column M do not have the inefficiency (slowness) of the whole-column-ref formula in G12 and calculate just as quickly as if the range was specifically set to go to row 23.
TRIMRANGE and Trim refs have a few options about trimming the range(s) but I have just used the option to trim off unused rows at the bottom of the data.

ajm.xlsm
ABCDEFGHIJKLMNOPQ
1Data1Data2Data3Data4Data5
2UNEDICCGRBCCGRB
3TNHNFCCXIBCCXIB
4CCGRBCOHSBCOHSB
5FEOUICAAAB
6PENOUCIPFB
7AYXLJ
8BYHJU
9CCXIB
10YGCVN
11MRGYP
12KFTKSCCGRBCCGRB
13GXEAXCCXIBCCXIB
14MAWLGCOHSBCOHSB
15BCWPICAAABCAAAB
16SHVFJCIPFBCIPFB
17COHSB
18KWOUA
19COIED
20YUGTR
21CAAAB
22XLHYG
23CIPFB
24
Sheet1
Cell Formulas
RangeFormula
G2:K4G2=FILTER(A2:E20,(A2:A20="C")*(E2:E20="B"))
M2:Q6M2=FILTER(TRIMRANGE(A:E,2),(TRIMRANGE(A:A,2)="C")*(TRIMRANGE(E:E,2)="B"))
G12:K16G12=FILTER(A:E,(A:A="C")*(E:E="B"))
M12:Q16M12=FILTER(A:.E,(A:.A="C")*(E:.E="B"))
Dynamic array formulas.
 
Upvote 0
@Peter_SSs, you might want to adjust the 2 TrimRange formulas to only Trim the whole range once and then use Index or ChooseCols to select the columns.
The current way of evaluating them independently means that if one of the columns drops short of the other column the formula will error out.
eg use something like.
Excel Formula:
=LET(rng,A:.E,
     FILTER(rng,(CHOOSECOLS(rng,1)="C")*(CHOOSECOLS(rng,5)="B")))

1738993398817.png
 
Upvote 0
@Peter_SSs, you might want to adjust ..
Hi Alex
Yes, I had thought of that and had drafted similar to your but with TAKE rather than CHOOSECOLS but not knowing what the OPs data or filters are and knowing that my columns were uniform, I decided to go for what I thought was a simpler formula to focus on the TRIMRANGE and Trim Refs concepts that I had introduced. :)
 
Upvote 0
Hi Alex
Yes, I had thought of that and had drafted similar to your but with TAKE rather than CHOOSECOLS but not knowing what the OPs data or filters are and knowing that my columns were uniform, I decided to go for what I thought was a simpler formula to focus on the TRIMRANGE and Trim Refs concepts that I had introduced. :)
Thank you both. does TRIMRANGE work to remove unused rows at the end in the same way as creating a dynamic named range? That is, it limits the used range to just that with data?
 
Upvote 0
Thank you both.
You're welcome, but three people have offered suggestions. :biggrin:

does TRIMRANGE work to remove unused rows at the end in the same way as creating a dynamic named range? That is, it limits the used range to just that with data?
More or less. You can read more about it & see examples here.
 
Upvote 0
sorry Vincent. I completely missed your response. Thank you also.
 
Upvote 0

Forum statistics

Threads
1,226,466
Messages
6,191,196
Members
453,646
Latest member
SteenP

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