Reputation: 13
I have Request URIs
in my GA
Page dimension that look like this:
I would like to create a calculated field in Tableau that extracts out the text prior to the first "?" and returns that value.
The ideal output based on the above input would be:
I tried this
Calculated Field: Formula: REGEXP_REPLACE(Page, '\\?.+', '')
It returns no records.
Please advise on either a workaround or explanation as to why Tableau doesn't process this as expected?
Upvotes: 1
Views: 183
Reputation: 1771
Instead of replacing characters to the right of the question mark, try extracting those to the left:
REGEXP_EXTRACT([Page], '([^?]*)')
Strangely, the above calculated field would not work without the parenthesis. Perhaps the same is true with your original attempts.
Edit: Because your original function seems to work for me, I'm curious if you're trying to use a datasource that does not currently support regex from Tableau.
Here is a list of datasources that support regex functions:
This function is available for Text File, Google BigQuery, PostgreSQL, Tableau Data Extract, Microsoft Excel, Salesforce, Vertica, Pivotal Greenplum, Teradata (version 14.1 and above), Impala 2.3.0 (through Cloudera Hadoop data sources), Snowflake, and Oracle data sources.
A way to do this natively in Tableau without using Regex would be the following:
IF CONTAINS([Page],'?') THEN
LEFT([Page], FIND([Page],'?')-1)
ELSE
[Page]
END
Be cautious, however, as the Contains() function is relatively computationally expensive - as it needs to search every character of every string.
Upvotes: 0