How can I make a single filter on Google Data Studio for multiple columns which contain dichotomus variable? - google-data-studio

I have a database that looks like this:
Var1
Var2
Tag 1
Tag 2
Local1
V1
0
1
Local2
V2
1
0
Local3
V3
1
0
Local4
V4
0
1
In Google Data Studio Report here; how do I put a single filter box where I can select the tag (title of the column of multiple columns) and only the rows that have a 1 in that rage of columns shows up?
The return of the filter would look like this When the filter selects Tag 1
Var1
Var2
Local2
V2
Local3
V3
And the return would look like this when the filter selects Tag 2
Var1
Var2
Local1
V1
Local4
V4
Sample data is here.

You set up an example for two columns, but in your sample you have many. Therefore, I show how to do it for two columns by selecting a number. But for the real case a parameter with a text list would be more user friendly, so they could see what they are selecting. All columns in the function are queried, so keep the costs for that in mind.
There is the need to use a parameter, lets call it tag_selected.
Create a field tag_filter with the columns you would like to select
case when tag_selected=1 then Anti-Corruption and Integrity
when tag_selected=2 then Audits
else 1
end
Finally create a filter to the table with the condition tag_filter =1

Related

Conditionally Sum a googlesheet column based on entries in related tables

Say I have two related sheets/tabs within a google sheet. One sheet/tab is titled "Categories", the other is "Measures".
Categories:
userid
catcode
1
a
1
b
2
a
3
c
Measures:
userid
catcode
points
1
a
5
1
b
5
1
c
3
2
a
4
3
c
3
For each user I'd like to be able to sum the points from the Measures table where the catcode is present for the user in the categories table. Ideally using an auto-extending/filling formula (like an arrayformula or query).
I have some idea how I'd approach this with SQL statements (joining the related tables, or doing a select where exists), but I'm new to googlesheets and would appreciate some direction here. I've experimented with this a bit and assuming a third table named "Users" with userids in column A, I can add this formula:
=sum(filter(measure!C2:C4, measure!A2:A4=users!A2, not(iserror(vlookup(measure!B2:B4, unique(filter(categories!B2:B5, categories!A2:A5=users!A2)), 1, false)))))
However this approach doesn't seem to be compatible with arrayformula and won't allow me to autofill down the Users tab for newly added userids. Sum itself is apparently incompatible with arrayformula. Additionally, if I enclose the above in arrayformula and replace sum with sumproduct or some other approach to the summation, I'm unable to get the users!A2 references to extend down as I'd expect via something like users!A2:A.
Any help/direction would be appreciated. Thanks!
Try:
=ARRAYFORMULA(QUERY({A1:A, VLOOKUP(A1:A&B1:B, {D1:D&E1:E, F1:F}, 2, 0)},
"select Col1,sum(Col2) where Col1 is not null group by Col1 label sum(Col2)''"))

Different drill through for each row

I have an SSRS report with several levels of drilling down. Data is aggregated up for the top level view, but I need to show a different drill down report depending on the type of one of the columns.
Eg:
Table 1 - Apples
Name Cost
Fuji 1.5
Gala 3.5
Table 2 - Squashes
Name Cost
Pumpkin 2
Gourd 4.5
I have a stored procedure which aggregates these and puts them in a table for the top level report to show. Ie:
Name Cost ItemType
Apples 5 1
Squashes 6.5 2
In reality, the two tables have different columns which I need to show in the drill through reports. Is it possible to look at the ItemType column and either drill down to one of two sub-reports, depending on it's value?
If you need to choose between two or more different sub-reports then make the ReportName property of the action on the textbox an expression like this.
=IIF(Fields!ItemType.Value = 1, "subReport_Apples", "subReport_Oranges")
if you have more than a handful SWITCH will probably be better
= SWITCH (
Fields!ItemType.Value = 1, "subReport_Apples",
Fields!ItemType.Value = 2, "subReport_Oranges",
Fields!ItemType.Value = 3, "subReport_Lemons",
True, "subReport_AnythingElse"
)
If you have a LOT of item types, consider adding the names of the subreports to your database creating a new table containing ItemType and subReportName. You can then join to this in your query and get the actual subreport name. The ReportName property of the text action would then simply be Fields!SubReportname.Value
You can add the ItemType as a parameter in your subreport(s). Then from your main report just link or jump to the sub report and pass along the Fields!ItemType.Value in the parameter configuration tab.

ORACLE SQL query to find data which are similar, but not exactly same

I am trying to search for data which are similar, but not exactly same, means that the data is not total duplicate.
I need to find the data for the column value PROJECTNAME,from the record PSPROJECTITEM, which contains two fields like this, AZ_HCM_901 and AZ_HCM_901_BKP.
So the field AZ_HCM_901 and AZ_HCM_901_BKP are similar, even the column value of these two fields are same, but they are not exact duplicate, i need a query to retrieve the values which are similar, and are separated by _BKP in the table along with the orignial.
!Table structure 1
And this is how the value looks like:
**AZ_HCM_901_BKP 0 1 ADDRESSES 0 0 0 0 4 4 3 1 1
AZ_HCM_901 0 1 ADDRESSES 0 0 0 0 4 4 3 1 0**
So we can see that the values are similar except for the column PROJECTNAME.
Also, AZ_HCM_901 is an example here, table contains the PROJECTNAME like this. I want to retrieve the values which are exactly like this, one original and one separated by _BKP
I want the data be in separate rows.
Thanks for the help.
SELECT proj_1.*, proj_2.*
FROM PSPROJECTITEM proj_1
INNER JOIN PSPROJECTITEM proj_2 ON concat(proj_1.projectname, '_BKP') = proj_2.projectname;

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.

yet another tsql question

i have three tables
documents
attributes
attributevalues
documents can have many attributes
and these atributes have value in attributevalue table
what i want in single query get all documents and assigned atributes of relevant documents in row each row
(i assume every documents have same attributes assigned dont need complexity of diffrent attribues now)
for example
docid attvalue1 attvalue2
1 2 2
2 2 2
3 1 1
how can i do that in single query
Off the top if my head, I don't think you can do this without dynamic SQL.
The crux of the Entity-Attribute-Value (EAV) technique (which is what you are using) is to store columns as rows. What you want to do is convert those rows back to columns for the purpose of this query. Using PIVOT makes this possible. However, PIVOT requires knowing the number of rows that need to be converted to columns at the time the query is written. So assuming you are using EAV because you need flexible attributes/values, you won't know this information when you write the query.
So the solution would be to use dynamic SQL in conjunction with PIVOT. Did a quick search and this looks promising (didn't really read the whole thing):
http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx
For the record, I am not a fan of dynamic SQL and would recommend finding another approach to the larger problem (e.g. pivoting in application code).
If you know all the attributes (and their IDs) at design-time:
SELECT d.docid,
a1.attvalue AS attvalue1
a2.attvalue AS attvalue2
FROM documents d
JOIN attributevalues a1 ON d.docid = a1.docid
JOIN attributevalues a2 ON d.docid = a2.docid
WHERE a1.attrid = 1
AND a2.attrid = 2
If you don't, things get quite a bit messier and difficult to answer without knowing your schema.
lets make example
documents table's columns
docid,docname,createddate,createduser
and values
1 account.doc 10.10.2010 aeon
2 hr.doc 10.11.2010 aeon
atributes table's columns
attid,name,type
and values
1 subject string
2 recursive int
attributevalues table's columns
attvalueid,docid,attid,attvalue(sql_variant)
and values
1 1 1 "accounting doc"
1 1 2 0
1 2 1 "humen r doc"
1 2 2 1
and I want query result
docid,name,atribvalue1,atribvalue1,atribvalueN
1 account.doc "accounting doc" 0
2 hr.doc "humen r doc" 1

Resources