Google Datastudio - Extract Values from Comma separated String - google-data-studio

I have a Sheet in which i import daily a CSV of reporting containing a column which contains comma separated values containing locations and a value
Item ID
Location results
112
Location A :1;Location B:3;Location C:4;Location D:1
113
Location A :5;Location F:1;Location X:9;Location Z:1
116
Location AA:3
I need to generate report in google datastudio that looks like showing the value after the : of that specific location. And i don't want to make too many manual changes every time to every sheet in Gsheets, so i hope that datastudio formula can solve this for me.
Another issue is that the Location names need to be an exact match as some names contain similar words like "Brussels North", "Brussels", "Antwerp North"
The news item ID is unique for each row
Any idea how i can get this data in datastudio?
Thank you
Tom
In Excel i got this to work via =IFNA(VLOOKUP($D$2:$D$7,TRIM(TEXTSPLIT(INDEX($B$2:$B$100,MATCH(E1,$A$2:$A$100,0)),":",";")),2,0),"")
I would need a view like this
Results view
Location
112
113
116
Location A
1
5
0
Location B
1
0
0
Location AA
0
0
3

Here's one approach:
as shown in the screenshot you can paste the raw csv import data in columns A, B
the arrayformula in D2 arranges the data that's compatible with the expected output in data studio
D2 formula:
=QUERY(ARRAYFORMULA(SPLIT(FLATTEN(A2:A&"|"&BYROW(B2:B,LAMBDA(hx,SPLIT(JOIN("",BYCOL(SPLIT(hx,";"),LAMBDA(ax,REPT(TRIM(REGEXEXTRACT(ax,"(.*):.*$"))&"|",--REGEXEXTRACT(ax,":(\d+)$"))))),"|")))),"|",0,0)),"Select * Where Col2!=''")
Connect columns D, E to data studio
Create pivot table with
Location as Row dimension
Item ID as column dimension
Item ID in metric with COUNT as aggregation

Related

EXCEL: Create Array Formula out of INDEX/MATCH with multiple results

my aim is to convert a massive excel sheet with different projects, employees and hours worked per month into an overview per employee. It should be possible to display the projects the employee is involved in and how many hours he worked per project per month.
The original sheet looks something like this:
I managed to find the projects Person A worked in by filtering through the INDEX/MATCH function. I applied the formula to the whole row where the employees are listed and receive multiple results of projects. My question is how to transform the formula into something more effective to copy all of the matched results (projects) into a column (see 1).
This is what I have so far, if matches the employee name in a certain area; the output is the first match of the project he is involved in:
=INDEX(B2:J3;1;MATCH("Person A";Sheet1!B3:E3;0))
How can I copy this to the bottom cells to copy all of the matched results? Does it help to create an array formula with this?
You can use he following formula in cell B9:
=IFERROR(INDEX($2:$2,SMALL(IF($3:$3=$B$8,COLUMN($3:$3)-COLUMN(INDEX($3:$3,1,1))+1),ROWS(A$1:A1))),"")
It indexes row 2 and looks for the column number of the first match in row 3 that equals the value in B8 (=Person A). When dragging down it will look for the second match ROWS(A$1:A1) will become ROWS(A$1:A2) = 2.
For Person B you can use this formula in cell B14:
=IFERROR(INDEX($2:$2,SMALL(IF($3:$3=$B$13,COLUMN($3:$3)-COLUMN(INDEX($3:$3,1,1))+1),ROWS(A$1:A1))),"")
I hope this is what you where looking for.
PS
if you paste the following formula in cell C9 you will get the sum result for Person A on Project XY in month 10 2019:
=IF(OR($B9="",C$8=""),"",SUMPRODUCT(($B$2:$K$2=$B9)*($B$3:$K$3=$B$8)*($A$4:$A$6=C$8),B4:K6))
Note: That is provided that the value in cell C8 equals the value in cell A4.

How to get the difference of a MINUS/subtraction function in Google Sheets

I am working with a CSV file and I need 100+ numbers which are all different to equal the number 10. I would something like a cell to look like this: 76 - ("Unknown" Number) = 10
The way the CSV file is set up, the first column is the item price (e.g 79.99), and it needs to equal 69.99 in the sale column, which I am trying to edit, and it displays $10 on our site. We have different prices for each product.
try:
=ARRAYFORMULA(IF(A2:A="",,A2:A-10))

How to check if specified date contains in records or not

I want something strange here. I've table names as EMP_INFO which contains few details of an employee (i.e. Name,Designation, JOIN_FROM, JOIN_TO). I am trying to figure out term for each employee on yearly basis. I've below types of data
EMP_ID EMP_DESIG JOIN_FROM JOIN_TO Query Result
1 Supervisor 01-05-11 30-04-13 Should Display
2 Supervisor 15-06-10 31-12-12 Should Display
3 Jobar 01-01-12 31-12-13 Should Display
4 SR Superior 01-12-11 31-12-15 Should Display
5 Supervisor 01-05-11 31-12-13 Should Display
6 Supervisor 01-05-11 31-12-13 Should Display
7 Supervisor 01-05-11 31-12-13 Should Display
8 Supervisor 01-02-12 15-06-13 Should Display
9 SR Superior 16-03-10 18-11-11 Should Display
10 SR Superior 16-06-05 18-11-11 Should Display
11 Jobar 30-11-11 31-12-13 Should Display
12 Superior 02-02-05 31-12-20 Should Display
13 Jobar 30-11-11 31-12-13 Should Display
14 Jobar 30-11-09 31-12-10 Should Not Display
Basically what i need is I have date range in my report and let's say From: "01-Jun-11" To "31-Dec-13". From above record set report should retrieve all records as all records contains this both dates.
I have tried by using BETWEEN syntax but i believe it will not work.
If anyone can help me in this than it would be appreciated.
Thanks in Advance.. And one more thing if this details is not enough to understand than let me know i will add more in details.
Modified
Query which I tried
SELECT EI.*
FROM EMP_INFO EI,
(SELECT
TO_DATE('01-JUN-2011','DD-MON-YYYY') A,
TO_DATE('31-DEC-2013','DD-MON-YYYY') B FROM DUAL) X
WHERE
(EI.JOIN_FROM IS NOT NULL AND EI.JOIN_TO IS NOT NULL)
AND (
X.A BETWEEN EI.JOIN_FROM AND EI.JOIN_TO
AND X.B BETWEEN EI.JOIN_FROM AND EI.JOIN_TO
OR (EI.JOIN_FROM >= X.B AND EI.JOIN_TO <=X.A) )
Modified Added column (Query Result) on above table which contains result for each record.
So you simply want all records where the join time is in the given time range? That would be:
SELECT *
FROM EMP_INFO
WHERE JOIN_FROM BETWEEN
TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN') AND
TO_DATE('31-DEC-2013','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN')
AND JOIN_TO BETWEEN
TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN') AND
TO_DATE('31-DEC-2013','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN');
EDIT: Sorry, I got it now. You are looking for all time ranges that overlap with the given range. That would be: ranges that start before and end within, ranges that start before and end after, ranges that start within and end within and ranges that start within and end after. Another way to express this is: Either the given time range start is within the other time range or the other time range start is within the given time range. Here is the according statement:
SELECT *
FROM EMP_INFO
WHERE JOIN_FROM BETWEEN
TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN') AND
TO_DATE('31-DEC-2013','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN')
OR TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN')
BETWEEN JOIN_FROM AND JOIN_TO;
And here is the SQL fiddle: http://sqlfiddle.com/#!4/b58b3/3
Convert to same format and compare. There may be a time component in the dates stored in database. Previous answer was wrong.

excel assemble two sheets exported from database

I have two sheet of excel exported from a database with hundreds of rows.
In first sheet I've these columns
name age gender
id1 23 m
id2 45 f
In second sheet these columns
id1 john smith
id2 jean ford
I'm looking for a macro or somethig else to automatically replace the idx in first sheet with the corresponding values from second sheet.
The final result should be a sheet like:
name age gender
john smith 23 m
jean ford 45 f
You don't need anything as complicated as a macro-- VLOOKUP will suffice:
Searches for a value in the first column of a table array and returns
a value in the same row from another column in the table array.
The V in VLOOKUP stands for vertical. Use VLOOKUP instead of HLOOKUP
when your comparison values are located in a column to the left of the
data that you want to find.
For example, if your id-sheet mapping was on Sheet2, then the formula
=VLOOKUP(A2,Sheet2.$A$1:$B$2, 2)
would look for the value found in this sheet's A2 cell in the leftmost column of the data table located in Sheet2.$A$1:$B$2, and then return the value from the 2nd column of that table. Copy that downwards, and get something like

How to write a query to see who called who the most in an Access database of phone calls?

I have a phone bill in Excel that shows all calls made to and from my phone and I imported it into a table in Access 2007. I want to learn to use Access to do a simple query to determine who I talk to the most.
Say we have Column A (caller) and Column B (person being called), and that my number will always be in either column. How do I make a query in Access to determine which phone number I talk the most with? I've got the Table with the Excel data in it, but I need some step-by-step handholding to learn how to do the query.
In simple english, I want to query all phone calls that contain my number in either column A or column B. Then, I want to count each unique pair (mynumber + othernumber or othernumber + mynumber should be counted under the same pair). Then, I want to count/summarize each unique pair to see which pair yields the highest count.
E.g. Go to Create ribbon, click Query Wizard, etc...
Thanks!
Lets say you have the following table :-
Column A : Column B
---------:----------
Fred : 1
Bill : 2
Fred : 1
You could do a query for example :-
SELECT A, B, Count(B) AS CountOfB
FROM Table1
GROUP BY A, B
ORDER BY Count(B) DESC
This would give you :-
Column A : Column B : CountOfB
---------:----------:----------
Fred : 1 : 2
Bill : 2 : 1
The first row would list the most common occurrences of column B and the count would list the number of times that row has been seen.

Resources