133 lines
11 KiB
Plaintext
133 lines
11 KiB
Plaintext
|
|
Episode: 1645
|
||
|
|
Title: HPR1645: 42 - LibreOffice Calc - Data Manipulation 2: Standard and Advanced Filters
|
||
|
|
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr1645/hpr1645.mp3
|
||
|
|
Transcribed: 2025-10-18 06:16:13
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
This episode of HBR is brought to you by AnanasThost.com.
|
||
|
|
Get 15% discount on all shared hosting with the offer code HBR15.
|
||
|
|
That's HBR15.
|
||
|
|
Better web hosting that's honest and fair at AnanasThost.com.
|
||
|
|
Hello, this is Ahuka welcoming you to Hacker Public Radio
|
||
|
|
and another exciting episode in our ongoing series on Libra Office Calt and continuing with data manipulation.
|
||
|
|
Last time we looked at sorting an auto filter and now I want to look at the other types of
|
||
|
|
ways you can filter stuff, standard and advanced filters.
|
||
|
|
Standard filter is something you can set from within the auto filter drop down or you can go there
|
||
|
|
through the data menu by selecting data then filter and then standard filter.
|
||
|
|
Now let's look at the question we ended the last tutorial with how many females over the age 40
|
||
|
|
had a case in 1978. We saw that we could get this by manually putting check marks in every age
|
||
|
|
that was greater than 40 using auto filter but how do we do this using standard filter?
|
||
|
|
Well if you had already filtered for 1978 and for female using auto filter you could go to the drop down
|
||
|
|
for any of the columns and select standard filter and this would bring up a window
|
||
|
|
and in the window you would see that the first that had filter criteria and the first row would say
|
||
|
|
the field name year condition is equal it's an equal sign value 78 and then the second row
|
||
|
|
has something we added and it is called an operator and the operator in this case is AND.
|
||
|
|
Field name sex condition equals value female.
|
||
|
|
So as just repeating what we've already done using auto filter the standard filter sees what you've
|
||
|
|
already applied. Now operator is important you can also select OR as an operator this is one of
|
||
|
|
those things you cannot do using auto filter. Auto filter everything is an AND.
|
||
|
|
If we selected OR as an operator here it would mean that we would select any case that occurred
|
||
|
|
in 1978 or any case that occurred involving a female. So we could have cases that involve
|
||
|
|
females that occurred in other years or we could have cases in 1978 that involved males.
|
||
|
|
The general rule to remember is that using AND reduces the size of your results and using OR
|
||
|
|
increases the size. So to get the answer we are looking for we need to add one more filter here.
|
||
|
|
So on line 3 select AND as the operator age as the field name greater than as the condition
|
||
|
|
and 40 as the value. Though there is a drop down for value you were better off just typing in 40
|
||
|
|
here the drop down just shows every value already existing in the age field and you may not have
|
||
|
|
the exact number you want in there. When you're done click OK and you will see the six cases we
|
||
|
|
noted previously. Another great advantage of using the standard filter is the increased flexibility
|
||
|
|
of the condition criterion. Using auto filter every filter is implicitly set to equal as the
|
||
|
|
condition. But the standard filter gives you a ton of options you can have equal less than greater
|
||
|
|
than less than or equal to greater than or equal to largest smallest those are interesting.
|
||
|
|
Largest is like the top 10 we saw in auto filter but you can specify a number other than 10 such as
|
||
|
|
the five largest values in the field and the opposite smallest is also available for when you need
|
||
|
|
to go in the other direction. Then there is largest percentage and smallest percentage. So you could
|
||
|
|
get the top 1% by using largest percentage with a value of 1 or a you know the bottom 5% whatever
|
||
|
|
the case may be. Then there are a number of things that are essentially string operations
|
||
|
|
contains does not contain. All right well so how does things like that work? For the field name select
|
||
|
|
sex the condition is contains and type in value EM. So it's going to look for any string that has
|
||
|
|
the letters EM somewhere in that string. Now in this case that's equivalent to selecting female.
|
||
|
|
So we could have just said equals female. Now does not contain goes the other direction. So if we took
|
||
|
|
the field name of race and the condition is does not contain and we type in the letters BL well
|
||
|
|
that would have the effect of filtering out everyone in the data set who is black. So
|
||
|
|
then there's begins with. So for the field name sex an example is condition is begins with
|
||
|
|
and type in value EM well that obviously that'd be equivalent to selecting equals male.
|
||
|
|
For the field name sex use the condition does not begin with and type in the value F and this
|
||
|
|
would also be equivalent to selecting equals male. And finally you've got ends with and does not end
|
||
|
|
with. If you understood the begins with you can figure out ends with. Now you can combine filters
|
||
|
|
in other ways. For instance suppose you wanted to select everyone in data set who is 21 years of
|
||
|
|
age or older but not older than 65. You would do this with two filters using the standard filter.
|
||
|
|
For the first one field name is age condition is greater than or equal to and type in a value of
|
||
|
|
21. Then for the second filter with a and we would say field name is age condition is less than
|
||
|
|
or equal and type in 65. Click OK and you have your answer. Now you can do the opposite type of
|
||
|
|
filter using the OR operator. To get everyone who is either younger than 21 or older than 65 make
|
||
|
|
the first filter age less than 21 for the second filter put in operator of OR field age condition
|
||
|
|
greater than value 65. This should give you the group that was excluded from the previous filtering.
|
||
|
|
And there is more. If you look at the lower left of the standard filter window you see more options.
|
||
|
|
Clicking this opens a bottom section to the window. Here you can make selections like case sensitive.
|
||
|
|
That can be useful if you need to distinguish strings which might have lower case and upper case
|
||
|
|
and you need to select on that basis. Range contains column labels. This should be checked by default.
|
||
|
|
Usually the first row contains the labels for each field and you would want them mixed up in the
|
||
|
|
filtering. Regular expression. This allows you to use regular expressions in any filter which is
|
||
|
|
said to either equal or not equal. In particular this is how you would use wild cards in your filter.
|
||
|
|
In the show notes I've put a link to a page that explains the regular expressions that are
|
||
|
|
supported in Calc. Now if you're a regular expression kind of person you probably realize that
|
||
|
|
every programming environment in existence has their own idea of what constitutes a regular
|
||
|
|
expression and how it works. So it's worth taking a look to see what Calc does and not just
|
||
|
|
charge in there saying oh I know regular expressions I don't need to read the manual.
|
||
|
|
Another thing in the more options. No duplication. Now this is duplication across an entire row.
|
||
|
|
So if you have two rows that are completely identical only one of them gets picked.
|
||
|
|
Finally copy results to. A very interesting option. This lets you apply a filter
|
||
|
|
then copy the resulting data to a new location. For example create a new sheet and give it a name
|
||
|
|
such as copied results from filter then set up a filter. In my sample spreadsheet I took the
|
||
|
|
filter that selected people under 21 or over 65. I clicked copy results to and then clicked on the
|
||
|
|
roll up icon on the far right of that row. I went to my new sheet clicked on cell A1 of that sheet
|
||
|
|
then clicked the roll down icon to return to my window and clicked okay all the results
|
||
|
|
could copy to the new sheet. One interesting change is that everything is renumbered. So what you
|
||
|
|
lose are the row numbers that you had in the original. The case numbers still stay there because
|
||
|
|
that's part of the data. Now with all of that with standard filter there's also something called
|
||
|
|
advanced filters. It's a very odd naming because in fact the advanced filters to my mind at least
|
||
|
|
seem a little simpler than the standard filters. So the idea is to do everything in the spreadsheet
|
||
|
|
you enter your criteria in cells of the spreadsheet. So I created a new sheet to do a filter using
|
||
|
|
the AND operator and copied it from the reduced data set sheet. Advanced filtering always assumes
|
||
|
|
you are operating on the data in the current page. So I moved over to columns I through N
|
||
|
|
selected the six cells on row one for those columns then clicked merge and center then I typed in
|
||
|
|
AND filter made it bold 12 point added a blue background you know just creating my header one of
|
||
|
|
those things I like to do. Under that on row two I copied my six column headers from my data set.
|
||
|
|
Then in row three I can just put in the criteria I'm looking for. If I'm using equals I can just
|
||
|
|
enter the value equals is assumed in other words but if I want to do anything using inequalities I
|
||
|
|
need to type that in. So in this row I type 78 under the year field greater than 40 in the age field
|
||
|
|
and male in the sex field. Once I have done this I can go to data menu to filter to advanced filter
|
||
|
|
and that's going to bring up my window and so first I'm going to highlight the range of cells that
|
||
|
|
contains the data. For my set it to cells A1 through F582 then go to data filter advanced filter
|
||
|
|
select the range of cells that have the column labels in the criteria which for my example is cells
|
||
|
|
I2 through N3. I click the roll up icon to the right of the range field then click and drag to
|
||
|
|
select this range then click the roll down icon and click OK and I get the result.
|
||
|
|
What this will do is hide every row that does not meet these criteria. In my example that
|
||
|
|
results in seven rows or seven cases selected. Now when doing an AND filter putting the criteria
|
||
|
|
on the same row will produce the results you want to get an OR filter put them on different lines
|
||
|
|
to replicate the one I did previously I set up a sheet with the data created a filter section
|
||
|
|
like I did above but in this case I entered less than 21 in cell L3.
|
||
|
|
L is the column for age in my filter criteria and greater than 65 in cell L4.
|
||
|
|
This will select everyone in the data set who is under 21 or over 65.
|
||
|
|
Execute the filter like the above example and in the one that I did I resulted in
|
||
|
|
395 cases being selected. Now you can do many of the same things using these two methods.
|
||
|
|
To me advanced is a bad name. The standard filter to my mind is more flexible and easy to work with.
|
||
|
|
The one advantage to advance that I can see is that you can have all the filter criteria
|
||
|
|
readily visible on the same sheet as the data and I can see that that is handy.
|
||
|
|
Still if I only had time to master one approach I would master standard filters.
|
||
|
|
Now I have once again created a sample spreadsheet that has the examples that I created
|
||
|
|
with this sample data set and the link to that is in the show notes. I invite you to download
|
||
|
|
and use it to your Hertz content and that means that this is a hookah signing off for Hacker
|
||
|
|
Public Radio and reminding you as always to support free software. Bye bye.
|
||
|
|
You've been listening to Hacker Public Radio at Hacker Public Radio.
|
||
|
|
We are a community podcast network that releases shows every weekday Monday through Friday.
|
||
|
|
Today's show, like all our shows, was contributed by an HBR listener like yourself.
|
||
|
|
If you ever thought of recording a podcast and click on our contributing to find out how easy it
|
||
|
|
really is. Hacker Public Radio was founded by the Digital Dove Pound and the Infonomicon Computer Club
|
||
|
|
and is part of the binary revolution at binwreff.com. If you have comments on today's show
|
||
|
|
please email the host directly leave a comment on the website or record a follow-up episode yourself
|
||
|
|
unless otherwise stated. Today's show is released on the create of comments,
|
||
|
|
attribution, share a light, free.O license.
|