Filter by Column Value

Analysis Guides

Filter by Column Value

The Filter by column value analysis enables you to filter a map layer by a selected column from your dataset. If you are familiar with using SQL, this is similar to a typical WHERE operation on a database. You can select the column to be filtered and define limits, or a range of values (depending on your data).

The Filter by column value analysis does not filter your map layer by a specified column. It filters and displays identified values within a single column. The analysis result displays rows that meet the criteria. This method of row filtering is a quick way to narrow down the total data being displayed.
While you can also use widgets to filter data, (or style a map layer by a column value), the Filter by column value analysis applies a temporary cache of filtered data to your map layer. This is useful if you are applying multiple analysis, improves the performance, and displays more granular details about your data.

For this guide, we will use maps created from other guides so that you can practice filtering layers by column values. Depending on the data of the column selected (string or numerical), different filter options can be applied.

It is important to understand the data type of your dataset columns. When you upload your data to CARTO, it automatically assigns a data type to your columns; such as string, number, date, or boolean. Certain styling is rendered based on the column data type. This is especially useful since you can filter and style map layers by column values in CARTO Builder.

Filter Data by a String Column

Apply the Filter by column value analysis as the next chain in the workflow for the Austin Fire Stations map. The map layer contains several types of identified data; such as fire stations, police stations, and hospitals. Our goal is to show only the fire stations for your layer.

  1. Create the map from this guide, about georeferencing street addresses. The map contains Austin Fire Stations as the first map layer and fragmented data as the second map layer.

  2. From the fragmented data layer, click the ANALYSIS tab.

  3. Click + from Your worflow, to add a second analysis to the chain.

    Add analysis to the workflow

  4. Select Filter by column value and apply the following options:

    • For COLUMN, select type. Once you select a column, additional parameters appear.
    • For INPUT, select Fire as the column value.
    • For RESULT, keep Show selected.
    Show and Hide options only appear when you are filtering by a string column.
    • SHOW - any rows matching the defined value appears on your visualization.
    • HIDE - any rows matching the defined value are hidden from your visualization.
    • Click APPLY.

The map layer refreshes and shows only the fire stations for your map layer.

Filter by column value applied

If you switch to the Data View of your map layer, only the rows that contain type=fire appear.

The Data View and Map View appear as icons on your map visualization when a map layer is selected. Click to switch between viewing your connected dataset as a table, or show the map view of your data.

Data view shows filtered rows

Filter Data by a Numeric Column

In this section, let's apply the Filter by column value analysis as the next chain in the workflow for the Thanksgiving Google Flight Searches map. The map layer contains the length output column, that was created as a result of the Connect with lines analysis. This column displays the distance between the airports from the origin cities to the destination. Our goal is to show only the flights less than specified distance away from the origin.

  1. Create the map from this guide, about origin flights from Miami during Thanksgiving. The map contains Flight Destinations as the first map layer, Origin City as the second map layer (with the Connect with lines analysis applied), and a copy of the original source of Origin City as the third map layer.

  2. In order to avoid any confusion between layers, rename the third map layer (layer C) to "Source".

    Double-click to rename map layer

  3. Click on the Origin City map layer.

  4. Click the ANALYSIS tab.

  5. Click + from Your workflow, to add a second analysis to the chain.

    Add analysis to the workflow

  6. Select Filter by column value, and apply the following options:

    • For COLUMN, select length. Once you select a column, additional parameters appear. Since this column contains numerical data, you can select the filter operation and define the values.
    • For FILTER, select is less than as the operation.

      Select the type of numerical operator

    • For VALUE, type in the 1621 as the maximum value. This indicates the distance in kilometers.

    • Click APPLY.

The map layer refreshes and displays only the flights that are less than 1621 kilometers from Miami.

Filtered flights by distance

If you switch to the Data View of your map layer, only the rows that contain the matching values appear.

Data View of filtered flights by distance