I am trying to create a report in SSRS. I have created a simple table report now I need to add a calculated field in that table. Below is that two fields which I need to use to create the calculated field.
type value
Credit Memo 3463
Invoice 2623
Invoice 3105
Invoice 3664
Invoice 2040
Credit Memo 2929
Credit Memo 2424
Invoice 2549
Invoice 2129
Credit Memo 2957
I need to put a if condition that is:
sum of values that has type Invoice - Sum of values that has type Credit Memo
I have created 2 calculated fields for that, first is:
SumOfInvoice==iif(Fields!new_documenttypeValue.Value="Invoice",(Sum(Fields!invoicedetail1_extendedamountValue.Value)),0)
Second is:
SumOfCreditMemo==iif(Fields!new_documenttypeValue.Value="Credit Memo",(Sum(Fields!invoicedetail1_extendedamountValue.Value)),0)
and then I added a column to the table and write an expression that :
=Sum(Fields!SumOfInvoice.Value)-Sum(Fields!SumOfCreditMemo.Value)
But It is giving me this error:
The expression used for the calculated filed SumOfInvoice includes an
aggregate, RowNumber, Running Value, Previous or lookup function.
Aggregate, RowNumber, RunningValue, Previous and lookup functions
cannot be used in calculated field expressions.
Can someone please help me with that??
Thanks
You can nest IIF inside SUM
Sum Of Invoice
=SUM(
Iif(Fields!new_documenttypeValue.Value="Invoice",Fields!invoicedetail1_extendedamountValue.Value,0)
)
The same for credit memos
=SUM(
Iif(Fields!new_documenttypeValue.Value="Credit Memo",Fields!invoicedetail1_extendedamountValue.Value,0)
)
Invoice - credit expression
= SUM(
Switch(
Fields!new_documenttypeValue.Value="Invoice", Fields!invoicedetail1_extendedamountValue.Value,
Fields!new_documenttypeValue.Value="Credit Memo",-Fields!invoicedetail1_extendedamountValue.Value,
True, 0
)
)
Or a more simple alternative since you only have invoice and credit memos could be
=SUM(
IIF(
Fields!new_documenttypeValue.Value="Credit Memo",
-Fields!invoicedetail1_extendedamountValue.Value,
Fields!invoicedetail1_extendedamountValue.Value
)
)
Related
Regarding MS Access, I need to add a Text box on a report that gets sum of a field conditional to another field value.
I.e.
I have a field named [clinic] another one named [clinic_income].
How can I calculate SUM of [clinic_income] only if [clinic] value = Dental clinic?
I tried this formula but it didn't work
Sum(
Filter(
'ALL'
Clinic = clinicInput. Dental clinic),
Clinic_income)
This is what IIf() is for:
=Sum(IIf([Clinic] = "Dental", [clinic_income], Null))
I created report in visual studio.The problem is with dividing by zero in total fields.
I have one column with value 00:03:15 and another column with 00:00:00
I want to sum these columns and want to show me average value from first and second column.
I used this expression ( formula ) in my case :
=Format(
TimeSerial(0,0,
Round(iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_INBOUND.Value/Fields!N_INBOUND.Value))
+
iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_HOLD.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_INBOUND.Value-Fields!N_TRANSFERS_TAKEN.Value),0))
+iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_CONSULT.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_CONSULT.Value-Fields!N_TRANSFERS_TAKEN.Value),0)))/count(Fields!PRESENTATION_NAME.Value))
, "HH:mm:ss")
I used this https://sqldusty.com/2011/08/01/ssrs-expression-iif-statement-divide-by-zero-error/ and looks like :
=Format(
TimeSerial(0,0,
Round(
iif(count(Fields!PRESENTATION_NAME.Value)=0,0,
(iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_INBOUND.Value/Fields!N_INBOUND.Value))
+
iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_HOLD.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_INBOUND.Value-Fields!N_TRANSFERS_TAKEN.Value),0))
+iif(sum(Fields!N_INBOUND.Value)=0,0,
sum(Fields!T_CONSULT.Value/Fields!N_INBOUND.Value)
+iif(first(Fields!HANDLING_TIME_MEASURE_TYPE.Value)=2,
sum(Fields!N_CONSULT.Value-Fields!N_TRANSFERS_TAKEN.Value),0)))/iif(count(Fields!PRESENTATION_NAME.Value)=0,1,count(Fields!PRESENTATION_NAME.Value)) ) ) )
, "HH:mm:ss")
But shows me an ERROR.Anyone who know how to fix that?
Your data is something like below, Correct me if I am wrong. At the Bottom I have added Total for both columns.
Note: You will have to take care of what type your column (T_INBOUND and N_INBOUND) return values.
Now to create a Total for T_INBOUND and N_INBOUND
To add totals for a column group In the tablix data region row group
area, right-click a cell in the column group area for which you want
totals, then point to Add Total, and click Before or After.
A new column outside the current group is added to the data region,
and then a default total is added for each numeric field in the
column.
Link:
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/add-a-total-to-a-group-or-tablix-data-region-report-builder-and-ssrs?view=sql-server-2017
Once you have Total you can create create a Cell Either next to your Total or below Total and add expression as below
IIF(IsNothing(Fields!Total_N_BOUND.Value) OR Fields!Total_N_BOUND.Value=0,0,
Fields!Total_T_BOUND.Value/Fields!Total_N_BOUND.Value)
I've this report
Here I make the first sum because I've grouped values from each month (months are "Gennaio", "Febbraio", "Marzo" etc etc.). These values are hidden, but anyway I get the sum and I display the sum for each month.
Then I should make the second sum that use values for each month and display the total for each category. Categories are "TOTALE LAVORI RESTAURO", "TOTALE LAVORI EDILE" etc.)
This is the final sum, where I sum values from each category.
Everything is working well, but now I have to add a "month" parameter to the report that returns sums until a selected month. This parameter changes the sum 1 with this expression:
=Sum(IIf(Fields!mese.Value <= Parameters!mese.Value, Fields!costi.Value, 0))
Now, how should I change expression in SUM2 and SUM3 to work with this parameter?
If I copy that code, ther returns #Error and as far as I know I can't use ReportItems sum.
So any suggestion?
SUM #1 could remain Sum(Fields!costi.Value) because you need to display every months.
i.e.: display GIUGNO even if Parameters!mese.Value = 4 (APRILE).
So you have only to change SUM #2 and #3 because TOTALE LAVORI RESTAURO and TOTALI must show only costi from GENNAIO to Parameters!mese.Value; i.e. if Parameters!mese.Value = 4 display only GENNAIO-APRILE even if we have details about GIUGNO.
The expression gave error because you have NULL value in Fields!costi.Value or Fields!mese.Value: convert this value to zero in your DataSet and you won't have problems.
I'm working with an access 2003 report that uses an employee, and their points they've accumulated over a period of time. When the report is run, it asks for parameters StartDate and EndDate, then generates a nice report by Supervisor -> Employee -> Each point with a reason.
How can I get a total box next to each employees name to give the total points for each employee? I've thought about writing a SELECT and WHERE statement and adding variables to the VBA, so the source property is:
=(SUM(SELECT [PointValue] WHERE [EmployeeName] = CurrentEmployee AND & _
[Date] <= #StartDate# AND [Date] >= #EndDate#))
Thanks in advance!
The easiest way to do this would be to use grouping. If you create a group header for the employee field (column) you can add a textbox and sum the points in the group header.
I basically want to create a payment schedule in a separate table based on 4 values that a user would select. The payment schedule is very basic and the table only needs 2 columns, 1) Date of payment, 2) payment amount.
The 4 criteria values that are used to fill out this simple table would be: 1) the total amount of money, 2) number of payments, 3) the frequency of the payments (monthly, quarterly, semi-annually, annually), 4) the date of the first payment.
The way that I envision this is having a Form where these 4 values will be selected. On that form there can be a button to execute the command to fill in a datasheet with the appropriate values.
The first entry would obviously be on the date of the first payment, and the amount for that entry would be the total amount divided by the number of payments. For the second record dollar amount would be the same and the date would be the first payment date + the frequency. So if the first payment date is 1/1/2000 and the frequency annually, then the second entry date would be 1/1/2001. Etc.. until the last payment is made.
While it is a pretty simple payment schedule, I'm not sure how to best approach this in Access and if it's even possible. Would appreciate some input and direction. Thank you!
You will need
-- A numbers table with integers from 0 to the highest number of payments possible, indexed on the number.
-- A combobox called Frequency on forms payments with the following properties:
Row source: q;quarter;m;month;ww;week
Row source type : value list
Bound column : 1
Column count : 2
Column widths : 0, 1
-- A query
INSERT INTO Payments ( UserID, PaymentDate, Payment )
SELECT [Forms]![Payments]![UserID],
DateAdd([Forms]![Payments]![Frequency],
[Number],
[Forms]![Payments]![Startdate]) AS Expr2,
[Forms]![Payments]![LoanAmount]/
[Forms]![Payments]![NumberOfPayments] AS Expr3
FROM Numbers
WHERE (((Numbers.Number)<[Forms]![Payments]![NumberOfPayments]));
-- A button to run the query.