Custom expression in Icon Settings based on two other columns - analytics

I have created a graphical table in spotfire
I have columns 'Group', 'Score', 'Pass/Fail'
I want to setup Alert Icon(Pass/Fail column) red or green circle base on Score. But pass-fail criteria is different for different groups. let say for group1 is 35% and group2 is 40%
How can I write a customer expression for this?
I cannot see the Group or Score as column to select in the "Customer Expression" window. I see only Axis.Icon in the 'Column' section
I was thinking of using something like this below in the icon setting custom expression
case
WHEN [Group] = 'Group1' and [Score] < 35 THEN Axis.Icon = 'Square' and Axis.Icon.Color = 'Red'
WHEN [Group] = 'Group2' and [Score] < 40 THEN Axis.Icon = 'Square' and Axis.Icon.Color = 'Red'
END
thanks

So that is not possible with Spotfire Icon settings to use multiple column. The workaround is that
I create a calculated column 'PW' in the data table having alphabetic value representation of conditional pass/fail based on group and score. i.e. p for pass and f for fail
I went to graphical table - icon setting for 'Pass/Fail' column, selected newly created column i.e First(PW) and then added new rule for pass and fail using 'start with' condition on to display a green or fail colored icons

Related

How to exclude in SQL with WHERE clause?

I have a WHERE clause in a large query that always exclude all records with the colour RED.
I however want to add another WHERE clause that exclude all records with the colour RED EXCEPT for when the age of the car is = 5.
Here's a some dummy data to better visualize how my data is built:
How would I integrate this into my large query to achieve this?
Here is my current query:
SELECT * FROM
TABLE1
WHERE COLOUR NOT LIKE '%RED%';
How would I modify this query to exclude all RED records EXCEPT when AGE = 5?
I am working in Snowflake.
The second condition needs to be connected using OR:
SELECT *
FROM TABLE1
WHERE COLOUR NOT LIKE '%RED%'
OR AGE = 5;

How to find the most frequently occurring value in SSRS tablix dataset?

Consider following dataset that is displayed in tablix in SSRS report:
GroupID | ProductID
---------------------
Group 1 | Product1
Group 2 | Product10
Group 1 | Product2
Group 3 | Product27
Group 2 | Product12
Group 2 | Product14
I added new row via Insert Row/Outside Group - Below.
On this row I display total number of rows - achieved via CountRows(), number of distinct Groups - achieved via =CountDistinct(Fields!GroupID.Value)
I also want to display the name of the group with the most number of rows, in this case it would be "Group 2" (in case if there is more than one group with the same number of rows I only need to display one of them).
How can this be achieved? I think I should use some of aggregate or lookup functions but so far can't figure out how.
PS This report is being ported from Crystal Reports to SSRS. In Crystal Reports this is easily achieved via "Nth most frequent" summary with N=1 but there is nothing like this in SSRS as far as I can tell.
Add a tablix and set GroupId as Row Group.
For Rows Count use:
=Count(Fields!GroupID.Value)
Right click GroupID group in the Row Groups pane and go to group properties, in the Filters tab use the following settings:
For Expression use:
=Count(Fields!GroupID.Value)
It will filter the top 1 group with the greatest Rows count. The result is something like this:
UPDATE: The previous solution doesn't work if there is more than one group with the same number of occurencies.
Add a tablix, delete the details (default group) and add the GroupID field in the first column.
For the Rows Count column use the following expression replacing DataSetName by the actual name of your dataset:
=LookupSet(
Fields!GroupID.Value,
Fields!GroupID.Value,
Fields!GroupID.Value,
"DataSetName"
).Length
Right click your tablix and go to tablix properties, in the Sorting tab select Z to A order and use the previous expression in the Sort By textbox.
It should show the only one group even if a second group with same number of occurencies is present.
Let me know if this helps.

Filter Columns based the condition of a Row

I have the following Matrix in SSRS 2008 R2:
What I would like to do is only show columns where the "FTE" row has a value. (Marked with red circles). I've tried the filter and show/hide options based on expressions in the Column Properties, but I can't figure out how to only reference the rows when "category"="FTE". My data looks like this:
tblPhysicians
employee_id last_name ...
102341145 Smith
123252252 Jones
tblPhysiciansMetrics
id fy period division_name category_name employee_id
123 2014 1 Allergy Overhead 123456
124 2014 1 Allergy Salary 125223
125 2014 1 Allergy FTE 1.0
query
SELECT * FROM
tblPhysicians
INNER JOIN tblPhysicianMetrics
ON tblPhysicians.employee_id = tblPhysicianMetrics.employee_id
WHERE
tblPhysicianMetrics.division_name = #division_name
AND tblPhysicianMetrics.fy = #fy
AND tblPhysicianMetrics.period = #period
Notice that the rows in my Matrix is just the category_name, so I can't just hide when category_name = "FTE", that's not really what I want. What I really need is some way of saying, "For rows where category_name = "FTE", if the value is not set, don't show that column". Is this possible?
An alternative would be to not even get those in the query, but as with the filtering of the matrix, if I simply add "AND tblPhysiciansMetrix.category_name = 'FTE'" to the WHERE clause, my entire data set is reduced to only those records where category_name is FTE.
Any help is much appreciated!
Update: added definition of Matrix to help:
You need to set the column visibility with an expression that checks all underlying data in the column for the FTE category.
I have a simple dataset:
And a simple matrix based on this:
Which looks exactly as you expect:
So in the above example, we want the Brown column to be hidden. To do this, use an expression like this for the Column Visibility:
=IIf(Sum(IIf(Fields!category_name.Value = "FTE", 1, 0), "last_name") > 0
, False
, True)
This is effectively counting all the fields in the column (determined by the last_name scope parameter in the Sum expression) - if this is > 0 show the column. Works as required:
CAVEAT I'm not 100% sure how you are grouping this data in the matrix. It isn't 100% clear from your description. Let me know why this doesn't work (if it doesn't and I'll update my answer accordingly.
I've replaced the column employee_id with the name value for my answer, to keep my explanation simple.
Add this nested IIF() to the visibility property of your Matrix's column.
=IIF(Fields!category_Name.Value="FTE" ,IIF( Fields!value.Value >= 0, True,False),false)
It will check both the value of the the category and the 'FTE' in that row's cell.

Report Builder 3.0 Charts - Need to show empty category groups

I am using SQL Server Report Builder 3.0 to create a bar chart. The chart is a count of satisfaction scores (Excellent, Very Good, Good, Fair, Poor), with a bar showing each of the respective scores. It works beautifully, except in the case where there are no records with a specific score. I would like to be able to show all of the options, even if there is a value of zero. Is there a way to put a placeholder there or otherwise force it to show?
Create another table that contains all of the category names.
CREATE TABLE CATEGORIES(ID NOT NULL PRIMARY KEY);
Then insert the category names into the table.
INSERT INTO CATEGORIES
VALUES ('Excellent', 'Very Good', 'Good', 'Fair', 'Poor');
Then for your bar chart dataset,
SELECT C.ID, COUNT(A.ID)
FROM Categories C
LEFT OUTER JOIN yourTableNameHere A on C.ID = A.category
GROUP BY C.ID;
The result will be a dataset with (CategoryName, Count) records.

Column and Row grouping in SQL Server Reporting Services 2008

This is the desired result I need to populate as a report, where xx is number of people.
I have a table which has fields like:
----------
table1
----------
id
state
year(as Quarter)
gender
I need to determine the count from id and populate as a report. The year is like 20081, 20082..20084 (in quarter).
I have created a dataset using this query:
SELECT STATE,GENDER,YEAR,COUNT(*)
FROM TABLE 1
GROUP BY STATE,GENDER,YEAR
From this query I could populate the result
ex: ca, m , 20081,3
ny, f , 20091,4
From the above query I could populate the count and using group by(row) state(in ssrs).
I need to group by (column). From the gender I get and by year.
How do I take the column gender and make it has Male and Female column?
Do I need to create multiple dataset like passing
where gender = 'M' or gender = 'F'
so that I could have two datasets, one for Male and One for Female? Otherwise, is there any way I could group from the Gender field just like pivot?
Should I populate result separately like creating multiple dataset for Male 2008, Female 2009 or is there any way I could group by with the single dataset using SSRS Matrix table and column grouping?
Should I resolve it at my Query level or is there any Features in SSRS which could solve this problem?
Any help would be appreciated.
Your SQL query looks good, but I would remove the quarter with a left statement:
select state, gender, left(year,4) as [Year], count(ID) as N
from table1
group by state, gender, left([year],4)
Then you have a classic case for a Matrix. Create a new report with the Report Wizard, choose "Matrix", then drag the fields across:
Rows: State
Columns: Year, Gender
Details: N
This should give you the required Matrix. Then replace the expression of the textbox with the Gender from
=Fields!gender.Value
to
=IIF(Fields!gender.Value="M", "Male", "Female")
Good luck.

Resources