If a report contains filters and a community connector returns unfiltered data for all fields requested then Looker Studio will apply filters to the connector response. However, filters can be applied at the community connector level which can significantly improve performance in some cases. Filter information is passed in the getData() request object, and the connector can use this information to filter data before sending it back to Looker Studio.
For example, if you're connecting to a SQL database, applying the filters
directly in the WHERE
clause (B3 in diagram below) can drastically decrease
the number of rows returned to Looker Studio. This, in turn, limits the amount
of data that has to be processed and sent to Looker Studio (B5).
Rules of applying filters
- Apply all filters, or none of them. See Unsupported filters
- Do not include
forFilterOnly
fields in the response. AND
together each entry in therequest.dimensionsFilters
array.For example, for the following filter, the connector should only include values that have a
country
ofUSA
AND asource
ofSocial
.{ "dimensionsFilters": [ [{ "fieldName": "country", "values": ["USA"], "type": "INCLUDE", "operator": "EQUALS" }], [{ "fieldName": "source", "values": ["Social"], "type": "INCLUDE", "operator": "EQUALS" }] ] }
OR
together each sub-array in therequest.dimensionsFilters
array.For example, for the following filter, the connector should only include values that have a
country
ofUSA
OR acountry
ofCanada
.{ "dimensionsFilters": [ [{ "fieldName": "country", "values": ["Canada"], "type": "INCLUDE", "operator": "EQUALS" }, { "fieldName": "country", "values": ["USA"], "type": "INCLUDE", "operator": "EQUALS" }] ] }
Example
The following example illustrates an end-to-end flow from the report user defining filters to the community connector returning filtered data.
The report user has configured two filters:
country
isIN_LIST
ofCanada, USA
source
isIN_LIST
ofSocial, Organic
The report user has configured a chart component with the
source
dimension andsessions
metricgetData()
is executed by Looker Studio with the following request object:{ "fields": [ {"name": "source"}, {"name": "sessions"}, {"name": "country", "forFilterOnly": true} ], "dimensionsFilters": [ [{ "fieldName": "country", "values": ["Canada", "USA"], "type": "INCLUDE", "operator": "IN_LIST" }], [{ "fieldName": "source", "values": ["Social", "Organic"], "type": "INCLUDE", "operator": "IN_LIST" }] ] }
Connector responds with filtered data.
For the example request, return the
source
andsessions
wherecountry
is"Canada"
or"USA"
AND thesource
is"Social"
or"Organic"
. SetfiltersApplied
totrue
since all filters were able to be successfully applied.
Original data
source | sessions | country |
---|---|---|
Social | 60 | USA |
Social | 50 | Canada |
Social | 40 | UK |
Organic | 90 | USA |
Organic | 80 | Canada |
Organic | 70 | UK |
Newspaper | 30 | USA |
Newspaper | 20 | Canada |
Newspaper | 10 | UK |
Filtered data
source | sessions |
---|---|
Social | 60 |
Social | 50 |
Organic | 90 |
Organic | 80 |
getData()
response
{
"schema": [
{"name": "source", "dataType": "STRING"},
{"name": "sessions", "dataType": "NUMBER"},
],
"rows": [
{"values": ["Social", 60]},
{"values": ["Social", 50]},
{"values": ["Organic", 90]},
{"values": ["Organic", 80]}
],
"filtersApplied": true
}
Unsupported filters
If the connector cannot apply all filters in the request, no filtering should be
performed. Return all of the requested fields (including the forFilterOnly
fields) and set the filtersApplied
key in your response to false
.
Example:
{
"schema": [
{"name": "source", "dataType": "STRING"},
{"name": "sessions", "dataType": "NUMBER"},
{"name": "country", "dataType": "STRING"}
],
"rows": [
{"values": ["Social", 60, "USA"]},
{"values": ["Social", 50, "Canada"]},
{"values": ["Social", 40, "UK"]},
{"values": ["Organic", 90, "USA"]},
{"values": ["Organic", 80, "Canada"]},
{"values": ["Organic", 70, "UK"]},
{"values": ["Newspaper", 30, "USA"]},
{"values": ["Newspaper", 20, "Canada"]},
{"values": ["Newspaper", 10, "UK"]},
],
"filtersApplied": false
}