SSRS expression for calculation using a specific value - ssrs-2008

I've attempted to create an expression which should calculate when a field equals 'Mid' and another equals 'Red' then calculate a percentage based on a field / specific number.
Here are my attempts so far:
=count(IIF(Fields!loc.Value="Mid" AND Fields!Status.Value ="Red",1,Nothing)) / count(Fields!Total.Value / 500) *100
=IIF(Fields!loc.Value="Mid" AND Fields!Status.Value="Grey",(FormatPercent (Count(Fields!Total.Value) / 500 ,0))
Expected results from the calculation would be a percentage: 34.83% (to two DP)
Loc field contains locations: Mid, Lon, Manc, Newc etc etc
Status field contains colours for statuses: Red, Green, Blue, Yellow etc etc Total field contains 'total' values for locations.
Neither seem to work and I'm getting myself confused. Once this one part is done, I can then add multiple locations and colours too.

Supposing a dataset like this:
Loc Status Total
Mid Red 100
Mid Red 200
Lon Blue 90
Manc Yellow 50
And you want to calculate the percentage of occurrences where Loc = "Mid" and Status = "Red" Using an expression like this:
=COUNT(
IIF(Fields!Loc.Value = "Mid" and Fields!Status.Value = "Red",Fields!Loc.Value,Nothing)) /
COUNT(Fields!Loc.Value,"DataSetName")
Replace DataSetName by the actual name of yours.
You will get 2/4 = 0.5 (50%) if you format the cell to a percentage number.
Hope it helps.

Related

conditional color coding of a textbox in SSRS Report based on date range

I have below columns in my report body and I need to fill background color in a ProviderNextContactDate textbox based on below condition
ProviderContactDate ProviderNextContactDate
2/3/2022 8/3/2022
1/6/2022 7/6/2022
11/18/2022 5/18/2022
..
if ProviderNextContactDate is past due then Red
if ProviderNextContactDate is within 30 days then yellow
otherwise transparent
Assuming past due means past on or earlier than today and your colums are Date or DateTime data types, then just set the backgroundcolor property of the textbox to an expression something like this...
=SWITCH(
Fields!ProviderNextContactDate.Value >=Today(), "Red",
DateDiff("d", Fields!ProviderNextContactDate.Value, Today()) <=30, "Yellow",
True, Nothing
)
The final 'True' acts like an else. 'Nothing' is the default backgroundcolor for textboxes which is effectively transparent.
You may need to adjust the numbers of days or the >= and <= depnding on your needs. For example, DateDiff returns the number of boundaries crossed, in this case the number of days (denoted by the "d").

Calculated field affected the Grand Total in Tableau

Used a calculated field by using the window_max and window_min functions:
IF
([eCPM]) = WINDOW_MAX(([eCPM]))
THEN "Least efficient" ////Red
ELSEIF [eCPM] = WINDOW_MIN(([eCPM]))
THEN "Most efficient CPM" ///Green
ELSE "Neither" ///Gray
END
But this also affected my Grand Total. I don't want any coloring in totals. How to handle this? (Solved)
Since my calculation is based upon eCPM, can only this column be highlighted as green rather entire row, without highlighting media cost and visits green as well?
Since my calculation is based upon eCPM, can only this column be highlighted as green rather entire row, without highlighting media cost and visits green as well?
You just need to "wrap" you if statement with another one in order to handle the grand total using size which returns the number of rows in the partition.
Using the superstore you can create a calculated field like this:
// Handle Grand Total
IF SIZE() = 1 THEN "Neutral"
// Handle all other "rows"
ELSE
IF sum([Sales]) = WINDOW_MAX(sum([Sales]))
THEN "Green"
ELSEIF sum([Sales]) = WINDOW_MIN(sum([Sales]))
THEN "Red"
ELSE "Neutral"
END
END
The result could look like this:

OrientDB Find vertex is linked with a list of another vertex

i am discovering OrientDB and i have a problem :
I have two vertex definition :
Product
Criterion
And one Edge definition:
- IsRelatedToEdge
Thanks to IsRelatedToEdge, I can link one product to many criterion
In my example, i have populated the database with 5 products
shoe-1
shoe-2
shoe-3
hat-1
hat-2
and 4 criterions :
blue
red
hat
shoe
Then I linked products with criterion this way:
shoe-1 <=> shoe
shoe-1 <=> blue
shoe-2 <=> shoe
shoe-2 <=> red
shoe-3 <=> shoe
shoe-3 <=> blue
hat-1 <=> shoe
hat-1 <=> blue
hat-2 <=> hat
hat-2 <=> red
so we have 2 blue shoe, 1 blue hat, 1 red shoe, 1 red hat.
I cannot figure out how to find all blue shoes.
EDIT : I have found a 'solution' but it doesn't looks good :
select from Product where
in('IsRelatedToEdge')[name="blue"].size() = 1 and
in('IsRelatedToEdge')[name="shoe"].size() = 1
IMO, the power of OrientDB lies in the graph abilities, and queries on a table/index do not really leverage this. I feel the best way to do this query is to get the shoe criterion, then get all of the products that have an edge to the criterion. From those products (ie all the shoes), you can now filter for ones that also have an edge to the blue criterion. One way to write this is as follows...
select *
from (select expand(both('IsRelatedToEdge')) from Criterion where name = 'Shoe')
let $blue_criterion = (select from Criterion where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]
Taking the above thought process further though, you could consider rearranging your data for better/easier querying. For example, you could make a Hat and Shoe class that are both subclasses of Product. That way to query on shoes, you query against the Shoe vertex class only. Similarly, you can make different criterion subclass, such as Color. To get blue shoes with such a config, the query would like the following...
select *
from Shoes
let $blue_criterion = (select from Color where name = 'Blue')
where both('IsRelatedToEdge') contains $blue_criterion[0]
You could even make more specific edges to take this a step further.
After studying neRok'solutions, i came at this solutions:
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$result = intersect($crit1, $crit2)
With this kind of query, I can add another criterion.
Imagine if we have anotehr criterion named adidas and i want to have all blue adidas shoes :
select expand($result)
let
$crit1 = (select expand(out('IsRelatedToEdge')) from Criterion where name='blue'),
$crit2 = (select expand(out('IsRelatedToEdge')) from Criterion where name='shoe'),
$crit3 = (select expand(out('IsRelatedToEdge')) from Criterion where name='adidas'),
$result = intersect($crit1, $crit2, $crit3)

Need to count a running value percentage top 80 percentile number of rows

I have a running value expression that color codes (Yellow) when it reaches 80%. The remaining 20% are then without color. I need to count the number of rows that comprise that 80%.
Here is the expression that's placed in the Background Color properties:
=IIF(RunningValue(Sum(CDbl(Fields!qtr_total.Value)), Sum, "Data8020") <
(Sum(Fields!qtr_totalValue.Value, "Data8020") * .8), "Yellow", "Transparent")
I just need to count the number of rows that are marked in yellow.
Add a column with the following expression:
=IIF(RunningValue(Sum(CDbl(Fields!qtr_total.Value)), Sum, "Data8020") <
(Sum(Fields!qtr_totalValue.Value, "Data8020") * .8), 1, 0)
and then sum this column to get to the count value. You can hide this column so that it wont mess the looks of your report.

Regarding Jasper report bar chart

I'm using jasper ireport 4.0.1 for developing. And I need to realize a bar graph being shown according to the imported 2 parameter one is for the used and the other is the total value. I want the left part of this bar represented in red color and the length will be changed according to the proportion of the used value out of the total also the used value need to be shown on this part of bar and the rest of the bar in green colour with the length regarding the total minus by the used value. How can I realize that, any help will be appreciated!
Let say the total value is 45
If the used value is 24 then the bar graph will show as follow
If the used value is 44 then the bar graph will looks like this
Regards,
You can achieve that by defining 2 parameters:
max: maximum value
proportion: value when it should switch between blue and green.
Then you add a stacked bar chart with 3 series:
Series1: series expression: "RED", category expression $F{<field>}, value expression $F{<value>}
Series2: series expression: "BLUE", category expression $F{<field>}, value expression $F{<value>} < $P{proportion} ? $P{max} - $F{<value>} : 0
Series3: series expression: "GREEN", category expression $F{<field>}, value expression $F{<value>} >= $P{proportion} ? $P{max} - $F{<value>} : 0