How can I filter out text from a date column?

Viewed 289

I have a column in Google Data Studio, which looks like this:

Date Rating
NULL NULL
NULL NULL
NULL NULL
NULL NULL
2022-01-01 11:44:19 9
2022-01-03 06:03:26 3
2022-02-03 06:03:26 4
2022-02-03 13:39:52 5
2022-03-03 13:41:33 2

The desired date format is dd/mm/yyyy (I don't really need the HMS). I'm trying to get the sum of each rating by month.

Sample data is here.

Sample report is here.

The "NULL" is not actually a null value but text. Because of this, the entire column is being treated as a text field. Is there a function that would ignore the "NULL" text values and only consider the dates, thus treating the field as a date format?

2 Answers

A three step approach is to first create a new date field (titled Date_Calc below), then filter out NULL values and finally change the field type from the default Date & Time to Date at the data source-level and to Month at the chart-level:

1) Date_Calc

Create the data source-level calculated field below which uses the PARSE_DATETIME function to "convert text to a date with time", with the input %F %T, where %F represent "the date in the format %Y-%m-%d" and %T is "the time in the format %H:%M:%S"; additionally, the function ensures that other values such as the text "NULL" would be converted to NULL values:

PARSE_DATETIME("%F %T", Date)

2) Filter

Exclude Date_Calc Is NULL

3) Additional Changes

This section looks at a core requirement (field type) as well as a few optional changes that could be made at the data source-level:

  • Field Type: Change the field type of the Date_Calc field from Date & Time to Date at the data source-level; the granularity can then further be changed at the chart-level (such as to Quarter, Year, Year Month or in this case, Month)
  • Hide Fields: The current text field, Date could be hidden at the data source
  • Rename Fields: The hidden Date field could be renamed to Date_Original and the Date_Calc field could be renamed to Date

Editable Google Data Studio Report (Embedded Google Sheets Data Source) and a GIF to elaborate:

8

Consider create a calculated field that has the following formula:

IF(LENGTH(Date)=4,"",Date)

Where "4" is the lenght of "NULL" word.

The previous formula checks the length of the Date field and (if the lenght is the same as the lenght of the NULL value), then, set a empty string1; otherwise, keep the original value of the Date value.

In your report example, I've created a field called NewField - which has the described formula above.


1 Instead of an empty string, you can set a default value, like 0001-01-01 or set another default value according to your needs.

Related