SSRS spatial Bubble map - Hide bubbles for 0 values - sql

In SSRS, when you add a map and select "Bubble map" in the wizard, the map will display bubbles for 0 values too.
I’m trying to visualize data as per follows:
It doesn’t matter if you count a field or sum. SSRS seems to show bubbles everywhere when there is a match on the spatial and the analytical table. Country_code in my case.
Can somebody please help me to hide the bubbles when the analytical data = 0 ?

I figured out how to do this with a little trick.
Right-click the map>Center Point properties>General>Click the function button next to the Marker type field and type the following expression:
=iif(Fields!Your_analytical_field.Value=0,"None","Circle")
Or if you want to do this only for null values:
=iif(Fields!Your_analytical_field.Value is nothing,"None","Circle")
That's it !
Don't know if this is the best way to accomplish what you need, but it's working anyway :)

Another way would be to filter your spatial dataset by joining with the analytical one. If using cube data, use openquery to join like that :
SELECT a.*
FROM
(SELECT your_geo_data, some_matching_id FROM SpatialData) a
INNER JOIN
(SELECT "[some hierarchy].[some_other_matching_id]" some_other_matching_id FROM OPENQUERY(YOUR_LINKED_SERVER, 'SELECT NON EMPTY { ... } on 0 FROM ... ' ) ) b
on a.some_matching_id = b.some_other_matching_id
The problem here might be performance as you would run the analytical dataset query twice, one for the analytical dataset itself and one for the join.

Related

Best practices for dealing with duplicate rows caused by unnested records in BigQuery?

Working with data coming from Facebook more often than not involves working with records where, in my case, all the “spicy” data is at. However, there is a downside, namely the huge amount of duplicate rows, which when not handled properly can cause over-reporting and/or data discrepancy.
Below is a use case which when joined with my primary data (coming from tables which do not involve any unnesting) causes a slight discrepancy in the final numbers.
Technologies used - Facebook Data -> Stitch -> BigQuery -> dbt -> Google Data Studio
I would usually create separate models where I’d unnest a record, transform the data and then join it into the rest of my models. An example of this is getting all website purchase conversion from the ads_insights’s actions record. 
Here is the difference though:

Query:
SELECT count(*) AS row_count
FROM ads_insights
Result:
 row_count - 316

Query:
SELECT count(*) AS row_count
FROM ads_insights,
UNNEST(actions) AS actions
Result:
 row_count - 5612

After unnesting, I’d use the row data to create columns for each conversion like so:
CASE WHEN value.action_type = 'offsite_conversion.fb_pixel_purchase' THEN COALESCE(value._28d_click, 0) + COALESCE(value._1d_view, 0) ELSE 0 END AS website_purchase

And finally I would join this model to the rest of my models. The only problem is that those 5600 rows cause a slight discrepancy when joined with the rest, and since I’ve already used the row data to create the columns, I don’t care about the unnested record data anymore, and I can go back to my original 316 rows. The only question is how? What techniques are out there that will help me clean up my model?
Solution:
Even though at some point I'd aggregate and group all the fields in my query like dylanbaker suggested in his answer, the discrepancy would still persist, and after doing a deep dive at my data I found that the unnested query will return 279 rows, whereas the nested one will return 314. This focused my attention at the unnesting query, where it will remove 35 rows, and those 35 rows happened to be null. After doing some google search I found this StackOverflow article which suggest using LEFT JOIN UNNEST to preserve all rows that have null record values, instead of CROSS JOIN UNNEST which will remove them.
You would typically want to do a 'pivot' here. You're most of the way there, you just need to sum and group by the relevant columns in order to get this back to the grain that you originally had and want.
I believe you'll want something like this:
select
ads_insights.some_column,
ads_insights.some_other_column,
sum(case
when value.action_type = 'offsite_conversion.fb_pixel_purchase'
then coalesce(value._28d_click, 0) + coalesce(value._1d_view, 0)
else 0
end) AS website_purchase
from ads_insights,
unnest(actions) as actions
group by 1,2
The initial columns would be whatever you want from the original table. The 'sum case whens' would be to pivot and aggregate the unnested data.
You can actually do some magic with unnests inside the select statement
Does this work for you?
SELECT
some_column,
(SELECT coalesce(_28d_click, 0) + coalesce(_1d_view, 0) from unnest(actions) WHERE action_type = "offsite_conversion.fb_pixel_purchase") AS website_purchase
FROM ads_insights

How to use aggregate function to filter a dataset in ssrs 2008

I have a matrix in ssrs2008 like below:
GroupName Zone CompletedVolume
Cancer 1 7
Tunnel 1 10
Surgery 1 64
ComplatedVolume value is coming by a specific expression <<expr>>, which is equal to: [Max(CVolume)]
This matrix is filled by a stored procedure that I am not supposed to change if possible. What I need to do is that not to show the data whose CompletedVolume is <= 50. I tried to go to tablix properties and add a filter like [Max(Q9Volume)] >= 50, but when I try to run the report it says that aggregate functions cannot be used in dataset filters or data region filters. How can I fix this as easy as possible?
Note that adding a where clause in sql query would not solve this issue since there are many other tables use the same SP and they need the data where CompletedVolume <= 50. Any help would be appreciated.
EDIT: I am trying to have the max(Q9Volume) value on SP, but something happening I have never seen before. The query is like:
Select r.* from (select * from results1 union select * from results2) r
left outer join procedures p on r.pid = p.id
The interesting this is there are some columns I see that does not included by neither results1/results2 nor procedures tables when I run the query. For example, there is no column like Q9Volume in the tables (result1, result2 and procedures), however when I run the query I see the columns on the output! How is that possible?
You can set the Row hidden property to True when [Max(CVolume)] is less or equal than 50.
Select the row and go to Row Visibility
Select Show or Hide based on an expression option and use this expression:
=IIF(
Max(Fields!Q9Volume.Value)<=50,
True,False
)
It will show something like this:
Note maximum value for Cancer and Tunnel are 7 and 10 respectively, so
they will be hidden if you apply the above expression.
Let me know if this helps.

How to write an expression for two different attributes in the same field in qlikview

Please help me write the script for the following statement in qlikview which I have it in SQL.
SELECT CASE
WHEN Total_A=0 THEN 0
ELSE cast(((Total_B+Total_C)/Total_A) AS decimal (5,2))
END AS ratio
I have Total_A , Total_B and Total_C in the same field called Total_val
The SQL CASE is usually replaceable by the QlikView if().
Try this
if(Total_A=0,0,(Total_B+Total_C)/Total_A) as Ratio
if the A,B,C switch is inside the Val column then it will get a lot more tricky as you will have to aggregate and use nested ifs. But I believe the statement I wrote is equivalent to the SQL you gave us. If my answer doesn't work please give us a few rows of data to look at

Qlik View: Get Values WHERE (value2 = max)

i have a relativly simple problem:
i have a Dataset that consists of an id(not for entry but for specific object), an age of the object and a power value.
So what i get is a lot of entries where there is a power at a specific age for a specific object.
I want to create a diagram that shows the average of all power values at the highest age over all objects(ids).
In SQl this basically would look something like SELECT power WHERE max(age).
Can anybody suggest a smart way how to this in a smart way in qlik view?
I already tried using the sum() function with total and aggr it over all ids but i keep getting weird results.
I tried using set analysis with aggr ({} power, id) but it doesnt work.
Edit: I tried
aggr(if (age= max(age), power), id)
but as soon as i select an id with more than one entry (different ages) there is no data displayed. Same when i remove the aggr function.
And:
Avg({$<age = max(age)>}Power)
Displays nothing at all (it also displays an error)
Also tried:
Sum({$ <age= {$(=max(age))} > } power )
Still nothing.
Thanks
Julian
Solved it with firstordervalue:
avg(aggr(firstsortedvalue (power, -age), id))
Yes Set Analysis should work.
Something like:
Avg({$<age = max(age)>}Power)
Alternatively, you can use a conditional sum as well:
if (age = max(age), avg(Power))
Aggr is used to run a statistic over a list of records with a 'group by' condition as in SQL

SQL MIN() returns multiple values?

I am using SQL server 2005, querying with Web Developer 2010, and the min function appears to be returning more than one value (for each ID returned, see below). Ideally I would like it to just return the one for each ID.
SELECT Production.WorksOrderOperations.WorksOrderNumber,
MIN(Production.WorksOrderOperations.OperationNumber) AS Expr1,
Production.Resources.ResourceCode,
Production.Resources.ResourceDescription,
Production.WorksOrderExcel_ExcelExport_View.PartNumber,
Production.WorksOrderOperations.PlannedQuantity,
Production.WorksOrderOperations.PlannedSetTime,
Production.WorksOrderOperations.PlannedRunTime
FROM Production.WorksOrderOperations
INNER JOIN Production.Resources
ON Production.WorksOrderOperations.ResourceID = Production.Resources.ResourceID
INNER JOIN Production.WorksOrderExcel_ExcelExport_View
ON Production.WorksOrderOperations.WorksOrderNumber = Production.WorksOrderExcel_ExcelExport_View.WorksOrderNumber
WHERE Production.WorksOrderOperations.WorksOrderNumber IN
( SELECT WorksOrderNumber
FROM Production.WorksOrderExcel_ExcelExport_View AS WorksOrderExcel_ExcelExport_View_1
WHERE (WorksOrderSuffixStatus = 'Proposed'))
AND Production.Resources.ResourceCode IN ('1303', '1604')
GROUP BY Production.WorksOrderOperations.WorksOrderNumber,
Production.Resources.ResourceCode,
Production.Resources.ResourceDescription,
Production.WorksOrderExcel_ExcelExport_View.PartNumber,
Production.WorksOrderOperations.PlannedQuantity,
Production.WorksOrderOperations.PlannedSetTime,
Production.WorksOrderOperations.PlannedRunTime
If you can get your head around it, I am selecting certain columns from multiple tables where the WorksOrderNumber is also contained within a subquery, and numerous other conditions.
Result set looks a little like this, have blurred out irrelevant data.
http://i.stack.imgur.com/5UFIp.png (Wouldn't let me embed image).
The highlighted rows are NOT supposed to be there, I cannot explicitly filter them out, as this result set will be updated daily and it is likely to happen with a different record.
I have tried casting and converting the OperationNumber to numerous other data types, varchar type returns '100' instead of the '30'. Also tried searching search engines, no one seems to have the same problem.
I did not structure the tables (they're horribly normalised), and it is not possible to restructure them.
Any ideas appreciated, many thanks.
The MIN function returns the minimum within the group.
If you want the minimum for each ID you need to get group on just ID.
I assume that by "ID" you are referring to Production.WorksOrderOperations.WorksOrderNumber.
You can add this as a "table" in your SQL:
(SELECT Production.WorksOrderOperations.WorksOrderNumber,
MIN(Production.WorksOrderOperations.OperationNumber)
FROM Production.WorksOrderOperations
GROUP BY Production.WorksOrderOperations.WorksOrderNumber)