Conditioned sum function in report - ms-access

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))

Related

How to fix the error dividing by zero in my expression in visual studio reports?

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)

Adding a simple calculated field in SSRS?

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
)
)

SSRS if day = Friday use dataset2

So I have an SSSRS REPORT with 2 data sets. If the day of the week is Friday I need to show the data in dataset 2 otherwise to use dataset 1. How can I accomplish this? is there a built in expression or function to do this???
You can't set DataSetName property at runtime, but you can select the data you want to return in your dataset based on the week day.
IF DATENAME(WEEKDAY,GETDATE()) = 'Friday'
select categoryDS1 Category, salesDS1 Sales from tableDS1
ELSE
select categoryDS2 Category, salesDS2 Sales from tableDS2
This will work if both SELECT statements have the same columns name
and types.
Let me know if this helps.
You can place a copy of both reports in the report and simply set the visibility for the one you want to show. The expression for the Visibility property for DataSet1 would be:
=IIf(WeekdayName(Weekday(Today)) = "Friday", True, False)
Swap the result for DataSet2.

SUM of a SUM in SSRS 2008

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.

SSRS Line Chart X-Axis group by Month

everyone. For the life of me I cannot figure out why the X-Axis is pulling 2 dates in each month when I want it to group by each month. In the Values I have:
Value Field =RunningValue(Fields!new_actualsalesfromsplit.Value, Sum, "Chart1_SeriesGroup")
Category Field: =Fields!closedate.Value
Category Groups =Month(Fields!closedate.Value)
Group On =Month(Fields!closedate.Value)
Series Group by ["salesperson']
The chart should have a line for each sales person, and each month should be a cumulative representation of the sales by that person. Thanks for any help.
Set the category field to "=Month(Fields!closedate.Value)", or something similar that will net the results you need. Right now, even though you're grouping by month, you're still telling SSRS to use the atomic data for your X axis, so that's what it's doing.
It may make your task simpler to just add a Calculated Field to your dataset - open the dataset properties window, go to the fields tab, and click "add". Set that field to your month value, use it for grouping and your X axis.