Get number of items in a field that contain specific text - google-data-studio

i have a field that lists all email address and i want to get the number of all email addresses with a certain domain, for example, "mydomain.com".
I can do this with a scorecard and a filter but I need to do this with a custom formula so i can also get the average. My finial goal is to get the average of "mydomain.com" email addresses vs. the total.
I tried this
COUNT(CONTAINS_TEXT(profile.email, "#mydomain.com"))
But, of course, this does not work.
Maybe a COUNTIF?
Bottom lime, i need to figure out how to get the number of email addresses from a specific domain in to a variable so i can then do some math on it ;)
I hope this makes sense.
Thank you!

Everything I've read points to using a CASE statement, however I've not actually managed to get one to work.
Here's the documentation: https://support.google.com/datastudio/answer/7020724

Related

How can i match and filter table by user input in data studio

I have a list of objects. In my case, the object is a contract (agreement). The contract has address field as string
I want to make it possible to filter by address. Or rather, the user enters the beginning or part of the address and the table is filtered based on the user input text. The problem is that the user can enter with a capital or small letter or something else, and thus strict equality does not work. I need a matching address with user input.
Data structure:
Input box controller:
This input box controller works only then user put exactly the same address as in data structure, for example Juhkentali tn 32, Tallinn. But my idea is, that user can enter only juhkentali and will see all contract with matched address
Please help me, how I could solve this problem.
I was facing the same issue. So I converted it to lower case using the lower function as commonly all searches are in lower case.
For example -
My data had a patient name column with the following values
Wagner,
ROBBINS,
doe,
junioR
So I converted the patient name column to lower case and used it in the input box. And, my visualizations used the original patient name column.
The only restriction with this is that the users have to search only in lower case.
Please let me know if this helps or if you got a better solution.

SQL Server validating postcodes

I have a table containing postcodes but there is no validation built in to the entry form so there is no consistency in the way they are stored in the database, sample below:
ID Postcode
001742 B5
001745
001746
001748 DY3
001750
001751
001768 B276LL
001774 B339HY
001776 B339QY
001780 WR51DD
I want to use these postcode to map the distance from a central point but before I can do that I need to put them into a valid format and filter out any blanks or incomplete postcodes.
I had considered using
left(postcode,3) + ' ' + right(postcode,3)
To correct the formatting but this wouldn't work for postcodes like 'M6 8HD'
My aim is to get the list of postcodes in a valid format but I don't know how to account for different lengths of postcode. Is this there a way to do this in SQL Server?
As discussed in the comments, sometimes looking at a problem the other way around presents a far simpler solution.
You have a list of arbitrary input provided by users, which frequently doesn't contain the correct spacing. You also have a list of valid postcodes which are correctly spaced.
You're trying to solve the problem of finding the correct place to insert spaces into your arbitrary inputs to make them match the list of valid codes, and this is extremely difficult to do in practice.
However, performing the opposite task - removing the spaces from the valid postcodes - is remarkably easy to do. So that is what I'd suggest doing.
In our most recent round of data modelling, we have modelled addresses with two postcode columns - PostCode containing the postcode as provided from whatever sources, and PostCodeNoSpace, a computed column which strips whitespace characters from PostCode. We use the latter column for e.g. searches based on user input. You may want to do something similar with your list of Valid postcodes, if you're keeping it around permanently - so that you can perform easy matches/lookups and then translate those matches back into a version that has spaces - which is actually a solution to the original question posed!

Grouping by the shortest common suffix in data

I have a table with a list of FQDN's, for example:
www.bbc.co.uk
bbc.co.uk
bbc.com
www.bbc.com
www.live.bbc.co.uk
www.live.bbc.com
I'd like to group these by the domain name; not the exact full domain name, but the shortest matching domain name that exists in the data. For instance, in the example above, I'd like to group
www.bbc.co.uk
bbc.co.uk
www.live.bbc.co.uk
together, as they have the common "suffix" of bbc.co.uk.
The fact that these are domain names is probably irrelevant, but might also play a part in the solution - can anyone suggest a way of GROUPing data together by the shortest common suffix?
EDIT: as requested, as an output I'd ideally like something like:
Domain Count
bbc.co.uk 3
bbc.com 3
If you do not know how many suffix to add in your grouping, it will be hard.
Maybe you can try to group by the last suffix (after the last dot).
Then if you got result, add the next suffix and group.
Then if you got result, add another one...
You can get the same amount of dots if you first convert the domain type to an IP address using nslookup. Link
Alternatively, there exists entire databases with list of known domain names. Link2
I've managed to bodge my way around the problem: I've introduced a temporary "MasterDomainName" field to the database, and I've updated it with:
UPDATE r1
SET r1.MasterDomainName= r2.domainname
FROM #results r1
LEFT JOIN #results r2
ON r2.domainname = right(r1.domainname,len(r2.domainname))
It's not perfect, but it gets me closed to where I need to be. Thanks for everyone's input.

Is there a limit to the number of items in a check box group?

I have a checkbox group for which I am using a #DbLookup to obtain the items to appear with checkboxes. It works fine except for a couple of cases where I am getting over 230 values from the lookup. In that case I get one checkbox with a value of "Infinity". I think that is telling me I have too many choices in my checkbox group.
Is there a limit to the number of values you can put in a checkbox group? What would be the best way to handle those cases where there is a large number of values? I may just take the route of "if there are more than 100 values returned, truncate the list".
There is no real limit for checkbox group. I tested it with 100000 entries and it still works well.
Probably, the "Infinity" error comes from #DbLookup. The error occurs if the result is larger than 64K. As an alternative to #DbLookup you can write your own SSJS code for getting the view entries or you use the Pure Java version of DbLookup & DbColumn, with cache, sort and unique.

How can I enter an e-mail address with a comma in it into a cell?

I'm trying to insert an email address with a comma in it (and it has to be entered that way) and I'm currently stumped on how to properly insert the exact text into this cell.
The e-mail address that needs to be entered as/is:
joe,.E.Blow#someemail.com
What I've tried is work different escape patterns into the code. For example, this...
'''joe'''+','+'''.E.Blow#someemail.com'''
gets entered into the database as...
'joe','E.Blow#someemail.com'
I've tried different combinations with single and double quotes and it can't even get past a simple parse without errors.
What is the best way to go about getting the email address entered as noted above? I know it's something simple but I'm just spinning my wheels here.
the solution is simple:
for example: joe,.E.Blow#someemail.com
SEE FIDDLE

Resources