I have Request URIs in my GA Page dimension that look like this:
/this/is/a/webpage.html?parameter=1
/forwarded/from?url=/webpage.html?parameter=1
/this/is/another/webpage.html
I would like to create a calculated field in Data Studio that extracts out the text prior to the first "?" and returns that value.
The ideal output based on the above input would be:
/this/is/a/webpage.html
/forwarded/from
/this/is/another/webpage.html
I tried this:
Calculated Field: Formula:
REGEXP_EXTRACT(Page, '^(.+?)\?')
It returns no records.
This is me playing with the regex https://regex101.com/r/hkqOXA/1
The regex seems valid, Data Studio seems to be failing me here! Please advise on either a workaround or explanation as to why Data Studio doesn't process this as expected!
Thanks!
Try this calculated field:
REGEXP_REPLACE(Page, '\\?.+', '')
The double back slash is the escape character for the question mark, then the calculated field grabs everything after that and replace it all with an empty string ''.
Cheers,
Ben
You can also do it this way.
REGEXP_EXTRACT(Page, '([^?]*)\?.*')
Related
I have a time series graph in Google Data Studio that connects to Search Console. In the graph I have a filter to only show search "queries" featuring a certain phrase. It works fine when I use one query. In the image I've blanked out the term as it's a clients brand name.
However when I add an OR element and then a second query the time series chart breaks.
When I add the second query it shows the error "Data Studio Cannot Connect to Your Data Set".
query 2:
Error message:
Tried it out earlier today using a Filter, and REGEXP_MATCH with a Pipe operator
|
For example, if you are searching for a Query that contains X or Y or Z, this does the trick:
Include Query RegExp Match .*(X|Y|Z).*
I can't tell you why - but I can tell you what's causing it and how to get round it.
The Search Console data source doesn't recognise the 'or' condition in the filter. To have an 'or' condition you need to add it as regex in your first condition
I created a field called Expr1 in a query to extract a particular string using the mid function from another field called HOME_CARD.
This HOME_CARD field has data like for example:
IA1234
IA6787
KL8900
MH5689
This is what I've tried to extract only the IA portion in my Expr1 field and it works.
Expr1: Mid([HOME_CARD],InStr(1,[HOME_CARD],"IA"),2)
My issue is, I am getting the #func! error in my query results besides the data like:
KL8900
MH5689
In MS Excel I could handle this issue by using an IFERROR in front of my formula so where IA is not found, the cell would just be blank.
Please help me friends, I rather want my query result for those without IA to be blank(empty) than return a #func!
Thank you in advance.
You can use Left:
Expr1: IIf(InStr([HOME_CARD],"IA")=0,Null,Left([HOME_CARD],2))
I am trying to extract id of Android app from its url but getting extra characters.
Using replace function in sql server, below are two sample urls:
https://play.google.com/store/apps/details?id=com.flipkart.android&hl=en com.flipkart.android
https://play.google.com/store/apps/details?hl=en_US&id=com.surveysampling.mobile.quickthoughts&referrer=mat_click_id%3Df1901cef59f79b1542d05a1fdfa67202-20150429-5128 en_US&id=com.surveysampling.mobile.quickthoughts&r
I am doing this right now:
SELECT
SUBSTRING(REPLACE(PREVIEW, '&hl=en',''), CHARINDEX('?', PREVIEW) + 4 , 50)
FROM OFFERS_TABLE;
But for 1st I am getting com.flipkart.android which is correct, but for 2nd I am getting en_US&id=com.surveysampling.mobile.quickthoughts&r.
I want to remove en_US&id from starting of it and &r from its end.
Can someone help me with any post or url from where I can refer?
What you are actually trying to do is extract the string preceded by id= until the & is found which is separator for variables in URL. Taking this condition I came up with following regex.
Regex: (?<=id=)[^&]*
Explanation: It uses the lookbehind assertion that is the string is preceded by id= until the first & is found.
Regex101 Demo
It seems like you've made some assumptions of lengths. The the &r is appearing because that is 50 characters. You are also getting the en_US because you assumed 4 characters at the beginning but your second string has more. Perhaps you can split on & and then look for the variable that begins with id=.
it seems like a function like this would help.
http://www.sqlservercentral.com/blogs/querying-microsoft-sql-server/2013/09/19/how-to-split-a-string-by-delimited-char-in-sql-server/
I try to implement a search-mechanism with "CONTAINS()" on a SQL Server 2014.
I've read here https://technet.microsoft.com/en-us/library/ms142538%28v=sql.105%29.aspx and in the book "Pro Full-Text Search in SQL Server 2008" that I need to use double quotes to search an exact phrase.
But e.q. if I use this CONTAINS(*, '"test"') I receive results containing words like "numerictest" also. If I try CONTAINS(*, '" test "') it is the same. I've noticed, that there are less results as if I would search with CONTAINS(*, '*test*') for a prefix, sufix search, so there is definitely a delta between the searches.
I didn't expect the "numerictest" in the first statement. Is there an explanation for this behaviour?
I have been wracking my brain about a very similar problem and I recently found the solution.
In my case I was searching full text fields for "#username" but using CONTAINS(body, "#username") returned just "username" as well. I wanted it to strictly match with the # sign.
I could use LIKE "%#username%" but the query took over a minute which was unacceptable so I kept looking.
With the help of some people in a chat room they suggested using both CONTAINS and LIKE. So:
SELECT TOP 25 * FROM table WHERE
CONTAINS(body, "#username") AND body LIKE "%#username%";
this worked perfectly for me because the contains pulls both username and #username records and then the LIKE filters out the ones with the # sign. Queries take 2-3 seconds now.
I know this is an old question but I came across it in my searching so having the answer I thought I would post it. I hope this helps.
Contains(*,'"test"') will only match full words of "test" as you expect.
Contains(*,'" test "') same as above
Contains(*,'"*test*"') will actually do a PREFIX ONLY search, basically strips out any special characters at the start of word and only uses the 2nd *.
You cannot do POSTFIX searches using full text search.
My concern lies with the Contains(*) part, this will search for any full text cataloged items in that entire row. Without seeing the data it is hard to tell but my guess is that another column in that row you think is bad is actually matching on "test" somewhere.
I'm trying to introduce LIKE clause with wildcards in SQL query that runs within Excel 2007, where parameters are taken from specific Excel cells:
SELECT Elen_SalesData_View.ItemCode, Elen_SalesData_View.ItemDescription,
Elen_SalesData_View.ItemValue, Elen_SalesData_View.Quantity,
Elen_SalesData_View.CustomerId, Elen_SalesData_View.CustomerName,
Elen_SalesData_View.SalesInvoiceId, Elen_SalesData_View.EffectiveDate,
Elen_SalesData_View.CountryId
FROM SM_Live.dbo.Elen_SalesData_View Elen_SalesData_View
WHERE (Elen_SalesData_View.EffectiveDate>=? And Elen_SalesData_View.EffectiveDate<=?)
AND (Elen_SalesData_View.CustomerName<>'PROMO')
AND (Elen_SalesData_View.ItemDescription LIKE '%'+?+'%')
The EffectiveDate parameters are running fine and bringing back data as expected. But since I introduced LIKE - query runs, but returns nothing.
It doesn't return any results without wildcards either (full description entered):
(Elen_SalesData_View.ItemDescription LIKE ?)
Is there a restriction to wildcards or LIKE clause? If so, is there a way around it? (I cannot use CONTAINS, as the ItemDescription field is not FULLTEXT)
Have a look at this reference which suggests that % itself is the wildcard character, although it may depend on the dialect of SQL you are using. If this is the case then your LIKE clause will simply be LIKE '%' but untested.
I've just got this to work by using the (Elen_SalesData_View.ItemDescription LIKE ?) syntax then having the cell that contains the parameter value include the wildcard characters. If you don't/can't include the wildcards then create a formula in a separate cell to wrap the value in % characters and use this cell for the parameter value.
Rhys
My query was correct. There was something wrong with the actual spreadsheet. After redoing all from scratch - it worked!
SELECT Elen_SalesData_View.ItemCode, Elen_SalesData_View.ItemDescription,
Elen_SalesData_View.ItemValue, Elen_SalesData_View.Quantity,
Elen_SalesData_View.CustomerId, Elen_SalesData_View.CustomerName,
Elen_SalesData_View.SalesInvoiceId, Elen_SalesData_View.EffectiveDate,
Elen_SalesData_View.CountryId
FROM SM_Live.dbo.Elen_SalesData_View Elen_SalesData_View
WHERE (Elen_SalesData_View.ItemDescription Like '%'+?+'%')
AND (Elen_SalesData_View.EffectiveDate>=?) AND (Elen_SalesData_View.EffectiveDate<=?)
AND (Elen_SalesData_View.CustomerName<>'PROMO')