Aristotle John Acorda
Aristotle John Acorda

Reputation: 13

How to remove GA Page query parameters using Tableau calculated fields?

I have Request URIs in my GA Page dimension that look like this:

  1. /this/is/a/webpage.html/?parameter=1
  2. /forwarded/from/?url=/webpage.html?parameter=1
  3. /this/is/another/webpage.html/

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:

  1. /this/is/a/webpage.html/
  2. /forwarded/from/
  3. /this/is/another/webpage.html/

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

Answers (1)

MonteCarloSims
MonteCarloSims

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

Related Questions