Reputation: 13
Question: How can I combine two data columns being used as separate filter controls into one single filter control without losing any values in Google Data Studio?
Example
Column A |
---|
ABCDE |
FGHIJ |
KLMNO |
GGGG |
Column B |
---|
PQRS |
TUVW |
XYZA |
GGGG |
Side by Side View - This is what the data looks like in tabular form:
Column A | Column B |
---|---|
null | ABCDE |
PQRS | FGHIJ |
TUVW | null |
XYZA | KLMNO |
GGGG | GGGG |
The coalesce function does not work because I am losing values where the two columns have different values - Coalesced Filter List will only include:
Missing Values:
Filter List Should Be:
Question Reiterated: I want to combine these two columns as one list to be used in a single filter dropdown in Google Data Studio without losing values.
Sample Data:
Upvotes: 1
Views: 3301
Reputation: 6471
The solution below is similar to the suggestion in the question How can I make single control field to control multiple columns in Google Data Studio?, where the CONCAT
function is used to join multiple fields (in this question, two fields titled Column A
and Column B
, respectively) by creating a single CSV (comma-separated values) field so that the CSV Filter Control Community Visualisation can be used to display and filter the required value(s); the difference being the possibility of NULL values in the fields:
CASE
WHEN Column A IS NULL AND Column B IS NOT NULL THEN Column B
WHEN Column A IS NOT NULL AND Column B IS NULL THEN Column A
WHEN Column A IS NOT NULL AND Column B IS NOT NULL THEN CONCAT(Column A, ",", Column B)
ELSE NULL
END
Column A
or Column B
can be viewed, when clicked)Note that the calculated field above can be shortened, for example, the first WHEN
:
WHEN Column A IS NULL AND Column B IS NOT NULL THEN Column B
could be:
WHEN Column A IS NULL THEN Column B
However, the purpose of the CASE
is to ensure that a single field (no support fields required) is created that also serves as self-documenting code, where each WHEN
clause is clearly understood by the editor or viewer, as all three WHEN
clauses are consistent, where the exact criteria is specified for Column A
and Column B
in all three instances.
Subsequently, the ELSE NULL
in this scenario, serves the purpose of:
WHEN Column A IS NULL AND Column B IS NULL THEN NULL
Publicly editable Google Data Studio report (embedded Google Sheets data source) and a GIF to elaborate:
Upvotes: -1
Reputation: 172993
I am pulling data from BigQuery using a custom query
Use below as a custom query
select distinct col
from your_table, unnest([ColumnA, ColumnB]) col
where not col is null
if applied to sample data in your question - output is
Upvotes: 0