SQL Server 2012 - SSRS Questions
I currently have a Pie chart that shows the number of deliveries as a percentage on whether they are late, on time or early. What I am trying to do is use an Expression in the Chart Series Labels "Visible" property to hide the label if it is 0 on the chat. Of note in the table this value is returned as 0.00 I have tried using various SWITCH and IFF Statements to do this but nothing seems to work and its likely I am getting the syntax wrong, can anyone help?
Table Values
TotalIssued Early Late OnTime EarlyPerc LatePerc OnTimePerc
6, 0, 4, 2, 0.00, 66.67, 33.33,
=SWITCH(
(First(Fields!EarlyPerc.Value, "EstimatesIssued") = 0),false,
(First(Fields!LatePerc.Value, "EstimatesIssued") = 0),false,
(First(Fields!OnTimePerc.Value, "EstimatesIssued") = 0),false,
true)
Thanks
Try:
=SWITCH(
First(Fields!EarlyPerc.Value, "EstimatesIssued") = 0,false,
First(Fields!LatePerc.Value, "EstimatesIssued") = 0,false,
First(Fields!OnTimePerc.Value, "EstimatesIssued") = 0,false,
true,true)
UPDATE:
If you have one field per percentage and your dataset returns one row always, you have to select each serie in the ChartData window and press F4 to see properties window.
In properties window set for EarlyPerc Visible property:
=IIF(Fields!EarlyPerc.Value=0,False,True)
And so on for the next two series you have (LatePerc and OnTimePerc).
Let me know if this helps.
Related
Trying to figure out conditional formatting for SSRS/Visual Studio and trying to get the figures to show this as an expression as follows;
Below benchmark needs to be Red
Above but within 5% needs to be Gold
More than 5% above needs to be Green
Benchmark 60%
Year 1 62.2%
Year 2 67.4%
Year 3 43.6%
First time in writing something like this so unsure what the best step is!
=iif("Textbox83" > "Textbox82", "SpringGreen", iif("Textbox83" < "Textbox82", "Red", iif("Textbox83" = "Textbox82" + 0.05,"Gold", "Transparent")))
A few things here..
Use SWITCH rather than nested IIFs, it much easier to read and debug.
You would normally work against the dataset fields rather than the textboxes displayed on the rendered report. If you do refence the textboxes, you probably have to convert the values to numeric before comparison
If you reference an object, either a dataset field or an rendered textbox, you must state the property you want, typical .Value
If this was being done against dataset fields you would do something like this
=SWITCH (
Fields!myValue.Value < Fields!Benchmark.Value, "Red",
Fields!myValue.Value <= (Fields!Benchmark.Value * 1.05), "Gold",
Fields!myValue.Value > (Fields!Benchmark.Value * 1.05), "Green",
True, Nothing
)
Switch stops at the first expression that results in True so the sequence of conditions is important. The final expression pair True, Nothing acts like an ELSE and returns nothing (which is the default backgroundcolor property, which appears as transparent)
If you wanted to replicate this using the textboxes (don't unless you really have to!) then it's basically the same but a bit more messy.
=SWITCH (
VAL(ReportItems!TextBox83.Value) < VAL(ReportItems!TextBox82.Value), "Red",
VAL(ReportItems!TextBox83.Value) <= (VAL(ReportItems!TextBox82.Value) * 1.05), "Gold",
VAL(ReportItems!TextBox83.Value) > (VAL(ReportItems!TextBox82.Value) * 1.05), "Green",
True, Nothing
)
The above is from memory and therefore untested but it should be OK.
I am having an issue with a divide by zero error that I have half way worked through.
Basically I need (EstimatedValuePlanned - EAC) / EstimatedValuePlanned
I have the following, however I am still getting #Error on some:
= IIF (Fields!EstimatedValuePlanned.Value = 0 , 0,
Fields!EstimatedValuePlanned.Value - Fields!EAC.Value)
/
SUM(Fields!EstimatedValuePlanned.Value)
I have changed the code around several times but I still either get Error or NaN
Thank you
IIF will always evaluate both parts of the function, so when SUM(Fields!EstimatedValuePlanned.Value) is zero you will get the error even though that's not what will be returned.
Try using a SWITCH statement. SWITCH stops once an expression returns True.
Something like this
= SWITCH(
SUM(Fields!EstimatedValuePlanned.Value) = 0 , 0,
True, (Fields!EstimatedValuePlanned.Value - Fields!EAC.Value) / SUM(Fields!EstimatedValuePlanned.Value)
)
The True expression simply acts like an else
UPDATE WITH SAMPLE
I created a new report added a dataset and set the dataset query to be the following (just to generate some dummy data).
DECLARE #t TABLE (EVP float, EAC float)
INSERT INTO #t VALUES
(1,2),
(2,3),
(5,4),
(0,2),
(1,0),
(0,0)
SELECT * FROM #t
I then added a table, set the first to columns to be EVP and EAC respectively and set the 3rd column to an expression as follows.
=SWITCH (
Fields!EVP.Value = 0, 0
, True, (Fields!EVP.Value - Fields!EAC.Value) / Fields!EVP.Value
)
The report design looks like this.
And when it's run this is the result....
Try replicating the above steps and see if you can get it to work like this first then review difference to your report.
I got it to work with:
=IIF (Fields!EstimatedValuePlanned.Value = 0 , 0,
Fields!EstimatedValuePlanned.Value - Fields!EAC.Value)
/
IIF(Fields!EstimatedValuePlanned.Value =
0,1,Fields!EstimatedValuePlanned.Value)
Thank you both
I have a table table of values displayed in SSRS .
The table has fields metricID , currentmonth , preciousMonth
Questions :-
1. I have to compare 2 values like current month and previous month
Fields.PreviousMonth.Value < Fields.CurrentMonth.Value
THEn Check if the metric id is metricID is 7 then increase in currentmonth should be displayed as up arrow with red colour else it should be downarrow with green colour.
For all other Metric ID's it should be "upp arrow with green colour" else "down arrow with red colour"
Does anybody have an idea on how to do this
To do this you will need to set up custom indicators and set an appropriate expression to set the indicator.
I have some simple data:
And a simple report with an indicator per row:
The indicator is set up as:
Where the expression is:
=Switch(Fields!MetricID.Value = 7 and Fields!CurrentMonth.Value - Fields!PreviousMonth.Value > 0, 1
, Fields!MetricID.Value = 7, 2
, Fields!MetricID.Value <> 7 and Fields!CurrentMonth.Value - Fields!PreviousMonth.Value > 0, 3
, true, 4)
So what I'm doing is assigning each row a specified state based on your business rules, and I've set appropriate icons for each of those states.
Report is working as required:
You could move the expression above into a calculated field in the Dataset if you needed to use it in multiple places in the report.
this one is my report
This is my result (but iddescripcion is not visible)
my question is.
how do i get when iddescripcion=1,3,5,8 or 10 then valor is going to have this format 10,000 (not decimals)
when iddescripcion=2,4,6, or 9 then valor is going to have this format 1,000.0 or 3,000.1( one decimal)
and when iddescripcion=7,11 then valor is going to have this format $2,389,012 (not decimalsa and $ before)
i believe the format i need add it at here but i do not have any idea how to do it..
You can apply condition formatting using a Switch or IIf statement in the Text Box Expression value.
I put a simple example together using the following expression:
=Switch(Fields!iddescripcion.Value = 1 or Fields!iddescripcion.Value = 2, Format(Fields!valor.Value, "N0")
, Fields!iddescripcion.Value = 3 or Fields!iddescripcion.Value = 4, Format(Fields!valor.Value, "N1")
, Fields!iddescripcion.Value = 5 or Fields!iddescripcion.Value = 6, Format(Fields!valor.Value, "$#,#"))
Basically just applying Format to valor based on iddescripcion for each row. This works for some simple data:
Hopefully you can adapt this for your example.
In a SSRS report my chart is linked to a dataset. However in the expression it says "Report item not linked to a dataset."
I like to hide the chart when no data is available. But because I cannot see the dataset it won't work. Even when I mention the dataset in the expression:
=IIf(Count(Fields!hostname.Value, "DataSetName")=0,True,False)
It gives me this error when I hover over "hostname.Value" => "Unknown collection member."
I've already remove the .data file because it was suggested here, but that doesn't work.
Anyone an idea?
You can set the charts visibility property by writing an expression using CountRows
= IIf (CountRows("dataset1") > 0, false, true)
or
= IIf (CountRows() > 0, false, true)
Or else go to the property window of the chart .You will see NoDataMessage expand it and in the caption mention
No data available
and set the property to false