New to SSRS. Using Report Builder 3.0. Trying to write a percentage expression.
This is the expression I have
=Sum(IIf(Fields!lastfinancialyearflag.Value=1,0,Fields!Total_Delivered.Value)) /
Sum(IIf(Fields!lastfinancialyearflag.Value=1,0,Fields!Total_Orders.Value))
I have highlighted the cell then, and formatted it to percentage, and 2 decimal places.
However I keep getting some cells showing NaN. I have read this happens when the value is 0, but I have e.g 1/4 gives me NaN error.
Is there a way to rid the NaN error, or a better way of writing the percentage expression please?
Note:
Total Orders / Total Delivered columns are 1 and 0 values
lastfinancialyearflag column is 1 and 0 values, but only want to sum where value is 1.
Please help!
You said "but only want to sum where value is 1." but your IIF expressions will return zero when lastfinancialyearflag is 1
try switch ing it round like this.
=Sum(IIf(Fields!lastfinancialyearflag.Value=1, Fields!Total_Delivered.Value, 0)) /
Sum(IIf(Fields!lastfinancialyearflag.Value=1, Fields!Total_Orders.Value, 0))
You have to make an extra check that the denominator (sum of total_orders.value) is not 0
=
Iif(
Sum(IIf(Fields!lastfinancialyearflag.Value=1,0,Fields!Total_Orders.Value))=0,
0,
Sum(IIf(Fields!lastfinancialyearflag.Value=1,0,Fields!Total_Delivered.Value))
)
/
Iif(
Sum(IIf(Fields!lastfinancialyearflag.Value=1,0,Fields!Total_Orders.Value))=0,
1,
Sum(IIf(Fields!lastfinancialyearflag.Value=1,0,Fields!Total_Orders.Value))
)
=
Iif(Sum(IIf(Fields!lastfinancialyearflag.Value=1, Fields!Total_Delivered.Value, 0))
=0
,0
,Sum(IIf(Fields!lastfinancialyearflag.Value=1, Fields!Total_Delivered.Value, 0)) /
Sum(IIf(Fields!lastfinancialyearflag.Value=1, Fields!Total_Orders.Value, 0)))
this worked, with a combo of using your guys answers.. thank you team A *
Related
I´m trying to do a query that will return only values that are multipliers of 90, to achieve this I need to end the query with something like "WHERE FIELD IS INTEGER", but can´t find a solution anywhere. Here is the query:
Select
name,
partnership_start_dat,
dateDiff("2020-03-01",DATE_FORMAT(partnership_start_dat, "%Y-%m-%d")) as "Partnerships Day",
dateDiff("2020-03-01",DATE_FORMAT(partnership_start_dat, "%Y-%m-%d")) / 90 as "Multiplier of Days"
FROM leme_account
WHERE dateDiff("2020-03-01",DATE_FORMAT(partnership_start_dat, "%Y-%m-%d")) / 90 = 1 (instead of value I need to say its integer)
Anyone can help?
Thanks!
Use the modulo function and check for it to be zero instead:
select name, partnership_start_dat,
dateDiff("2020-03-01",DATE_FORMAT(partnership_start_dat, "%Y-%m-%d")) as "Partnerships Day",
dateDiff("2020-03-01",DATE_FORMAT(partnership_start_dat, "%Y-%m-%d")) / 90 as "Multiplier of Days"
FROM leme_account
WHERE mod(dateDiff("2020-03-01",DATE_FORMAT(partnership_start_dat, "%Y-%m-%d")), 90) = 0
That should work. I haven't tested the query, just changed the condition.
You need the modulo operation, sometimes called the remainder operation, to do this.
For example the value of 270 % 90 is 0. The value of 93%90 is 3.
To test whether a number is evenly divisible by 90, you use (number % 90) = 0.
I am trying to get a sum of people of a specific age. AgeInYears is a Decimal.
I have tried a sum and get 0 every time
=SUM(IIF( Fields!AgeInYears.Value = 15, 1, 0 ) )
If I do a count I get 68 which is still incorrect
=Count(IIF( Fields!AgeInYears.Value = 15, 1, 0 ) )
I'm not sure if I am comparing to a decimal correctly. When I use my query in SQL, then use a pivot table on the data I'm able to find the answer as 47 (I'm much better with excel than SSRS). But in SSRS I can only get a 0 or 68 Value.
EDIT
I am calculating the AgeInYears myself in my Query via
cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) as AgeInYears
could this be related?
I was unable to solve whatever issue that SSRS was giving me when I attempted to count the ages.
Instead I have updated my query to
Select
cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) as AgeInYears
From Table
Where
cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) > 13
and
cast(cast(datediff(month, invl.ChildDateOfBirth, fp.enddate) as decimal) / 12 as decimal) as AgeInYears < 19
This ensures my data only contains ages that I want ( between 14-18.
Then in the SSRS table I created a row group over AgeInYears and did a simple
=Count(Fields!AgeInYears.Value)
in the text box to get the correct count for each Age.
I am creating a student report card in ms access and there are five texboxes which can either be fill totally or few of them can be left unfilled. I have applied a formula through expression builder to add all the values in those five fields and display the calculated result in that specifix textbox.
But the problem here is that the textbox is not showing the result untill all the values are filled. If any of those five boxes remain null, the calculated result wont show up.
Here is the formula
[mo1]+[mo2]+[mo3]+[mo4]+[mo5]
and being stored in [Totalmarks]
I have also tried using the update query but the result remain the same. kindly help in this regard. Thanks
Null plus anything yields Null.
You can use Nz Function to substitute zero for Null when adding the textbox values.
Nz([mo1], 0) + Nz([mo2], 0) + Nz([mo3], 0) + Nz([mo4], 0) + Nz([mo5], 0)
dude you might be using a calculated field in the expression builder. take the values from the actual data cell, not a calculated one
for example
amt xx
tax xxx
total = amt + tax
advance = yy
then,
balance = amt + tax - adv (this is correct)
balance = total - adv (this is wrong)
dont know the reason behind it, but it worked for me.
I have some column in my report, calculated the Sum using this exepression :
=SUM(IIF(Fields!Type.Value = 0, CDbl(Fields!Amount.Value), CDbl(0.0)))
it works but gives me the sum with no precision.
is there a way I can view the Sum with precision?
UPDATE
the Fields!Amount.Value is alway decimal(18, 3)
If The calculation was like sum = 10 + 10 the result becomes 20
if sum = 10 + 2.125 the result becomes 12.125
I want the result to be converted to (18, 3).
so I expect the result in the first example to be 20.000
Your report is correctly returning the values to the necessary precision, it is just only showing the significant figures because you have not told it what number formatting you require and is making a best guess.
If you change your expression to the below, you should get your desired output:
=FORMAT(SUM(IIF(Fields!Type.Value = 0, CDbl(Fields!Amount.Value), CDbl(0.0))),"0.000")
I have a dataset which contains phone data for a given period, i need to filter this data based on the hour of the day so i can use this in a chart which shows the peak periods.
So far, i have this expression:
=Count(IIF(DatePart("h", Fields!CallStart.Value = 7), Fields!ID.Value, 0))
So, what i had hoped this expression would do is replicate this SQL Query:
select * from PhoneData
where MONTH(callstart) = 7 and YEAR(callstart) = 2012 and DATEPART(HH, callstart) = 7
and Direction ='i' and Part1Device not like 'v%' and Continuation = '0'
The month and year are set in the dataset query.
Suffice to say, the expression doesn't work and i can't quite figure out why.. any help would be greatly appreciated.
Looks like your closing bracket for the DatePart function is in the wrong place. Try this.
=Sum(IIF(DatePart("h", Fields!CallStart.Value) = 7, 1, 0))