SQL Server Report Builder SUM IF - sql-server-2012

I have a table which display various data and what I want is it to calculate a percentage in which the total has increased by, so for example:
Total is £1000
TotalAfterMarkup is £1500
=SUM(Fields!Total.Value -
Fields!TotalAfterMarkup.Value) /
(Fields!TotalAfterMarkup.Value)
the above code calculates the Percentage to -50% which is incorrect but ill be able to work that out. What i want is to now put this statement into an SUM IF statement. currently i get the #Error if the TotalAfterMarkup < 1 so i need something like
IF TotalAfterMarkup.Value >0 THEN
=SUM(Fields!Total.Value -
Fields!TotalAfterMarkup.Value) /
(Fields!TotalAfterMarkup.Value)
ELSE 0.00%
is this possible, thanks for any help guys

Unfortunately I don't have enough rep to comment, otherwise I wouldn't post this as an answer. Really, I need a little more information. Are you doing this as an expression within the report builder or as part of your dataset?
If its part of your dataset then I suggest using a case statement.
case
when TotalAfterMarkup.Value >0
then SUM(Fields!Total.Value -
Fields!TotalAfterMarkup.Value) /
(Fields!TotalAfterMarkup.Value)
else '0.00%'
end [MyFieldName]
Using an IIF Statement: ("Dataset = Your Dataset Name")
=IIF(Fields!TotalAfterMarkup.Value, "CostTable") >0, SUM(Fields!TotalCost.Value, "CostTable") - (Fields!TotalAfterMarkup.Value, "CostTable") / (Fields!TotalAfterMarkup.Value, "CostTable"), "0.00%")

I think this should work:
=IIF(TotalAfterMarkup.Value > 0,(SUM(Fields!Total.Value -
Fields!TotalAfterMarkup.Value)/(Fields!TotalAfterMarkup.Value)),0)
The IIF function is the one you use for evaluating conditions in SSRS:
Expression Examples (Report Builder and SSRS) - See decision function section

Related

SSRS Division issue in column grouping

Problem: Having trouble getting an accurate division on a "sub-matrix" when using drill down, works on totals but not detail level.
Report:
Visual Studio Design of the report:
Now the current SSRS expression I'm using in the "% Of total" section is:
=Code.SafeDivide(Fields!Orders.Value , Sum(Fields!Orders.Value))
and the embedded code was a recommendation from this post:
Public Function SafeDivide(ByVal Numerator As Decimal, ByVal Denominator As Decimal) As Decimal
If Denominator = 0 Then
Return 0
End If
Return (Numerator / Denominator)
End Function
Data results looks like:
Now if you look at the first picture and calculate the divison of the highlighted values, i would expect the outcome to be 72% not 6%.
Any ideas? Maybe i've tried a few things but seem like im chasing my tail, would of though this would be simply straight forward.
It looks like you need to pass in a sum rather than a single order amount, and then tell your existing sum function the overall group to sum e.g. I think your expression should probably be something like this:
=Code.SafeDivide(Sum(Fields!Orders.Value), Sum(Fields!Orders.Value, 'Overall Group Name'))

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

Calculate SUM of column based on another column SSRS

I am working on creating a SSRS report that requires me to "have a column that gives me the number for the offer and out of that number how many enrolled." I have attached a screenshot of what I have done so far. I need to figure out how to create an expression (if there is a better way to go about this) that would use following logic: Get SUM of Count column where Enrolled = 'Yes'. Is this possible in SSRS?
Right now your summary expression probably looks something like this
= Sum(Fields!Count.Value)
If so - all you need to do is add a condition include only records with Enrolled = "Yes"
= Sum(IIF(Fields!Enrolled.Value = "Yes", Fields!Count.Value, 0))

SQL Report Builder: get value from group within tablix

Please forgive the vague title of this question. Perhaps the below will ask my question better.
Consider the below aggregated table:
Fruit Units FruitSales%
----- ----- -----------
Apples 10 ?
Oranges 20 ?
Bananas 10 ?
NonFruit 10 ?
TOTAL 50 ?
I need the FruitSales% column to be: Fruit / (Total - NonFruit)
If NonFruit is a product name of its own, how do I get its value for use in other calculations in the tablix?
I imagine my formula for the FruitSales% is something like:
Sum(Fields!Units.Value) / (ReportItems!txtTotalUnits.Value - SumIf(Fields!Fruit = "NonFruit", Fields!Units.Value)
However, SumIf does not exist and even if it did, it would be specific to the current row.
And while I'm here, ReportItems!txtTotalUnits.Value, I have obviously named that text box, but is there a cleaner way to reference it?
Say the underlying DataSet (which I've called FruitDataSet) looks like this:
I've created a simple report based on this data:
The Fruit Sales % expression is:
=Sum(IIf(Fields!fruit.Value <> "NonFruit", Fields!units.Value, 0))
/ Sum(IIf(Fields!fruit.Value <> "NonFruit", Fields!units.Value, 0), "FruitDataSet")
This gives what I think is the correct results:
There are two things to note about the expression:
By running the Sum against an IIf expression, you can control what gets included in the totals - here I'm setting NonFruit explicitly to 0.
By setting the Scope of the aggregate expression, you can get overall totals to use to work out total percentages - in the report I'm getting a total using FruitDataSet and comparing this to the group-level total to get a % value.
The way you're referencing the textbox total is fine; the only other option would be to use an expression each time you want the total - if this is outside a Tablix you would need to explicitly set the Scope, e.g. the DataSet.

Ms Access : Query to work out percentage

I have a database which currently records the amount of times someone does a certain procedure and they scores they have received. The scoring is done by select a value of either N, B or C.
I currently have written a query which will count the total number of times a procedure is done and the amount of times each score is received.
Here is the result of the query (original: http://www.flickr.com/photos/mattcripps/6673555339/)
and here is the code
TRANSFORM Count(ed.[Entry ID]) AS [CountOfEntry ID]
SELECT ap.AdultProcedureName, ap.Target, Count(ed.[Entry ID]) AS [Total Of Entry ID]
FROM tblAdultProcedures AS ap LEFT JOIN tblEntryData AS ed ON ap.AdultProcedureName = ed.[Adult Procedure]
GROUP BY ap.AdultProcedureName, ap.Target
PIVOT ed.Grade;
If a score of N or B is given that is deemed below standard and C is deemed at standard. Is there a way I can add something to my query which will show me in percentage how many of the procedures we at standard and how many below?
I really cant get my head round this so any help would be great.
Thanks in advance
UPDATE TabProd
SET PrecProd = (PrecProd * 1.1)
WHERE Código IN (1,2,3,4)
I did something very similar to this on a pretty large scale.
My issue was the need to be able to run queries over specific (but user variable) timeframes and output similar percentage of total results in a report.
I won't get into the date issue but my solution was to run the "sum" function on the total line on my specific reject criteria to get totals of the rejects then use a divide expression to create a new column element (defined expression) in the same query pulling from the joined table of "Total net production" - joined by a common reference - job ID.
For your case it sounds like you want to sum the two failure types - which you would simply add defined expressions dividing your total instances into your various failure modes and formatting in your output report as percents. To finish the data portion of your report you then need a third expression defining your "non-fail percent" - which would be 1.0 - N/total - B/total - both of which you will have previously defined in the query to determine the N and B failure rates.
Then its a matter of pulling that information into your report and formatting. It definitely CAN be done.
Hope this helps.