I'm using a matrix to show salespersons orders for each month of the year.
rows - state, salesperson name
columns - year, month
data - number of orders
for each salesperson I have the total number of orders per year.
based on that I have a calculation that shows if the salesperson met his target or not.
=IIf(sum(Fields!OrderCount.Value)>=50, "met target", "below target").
I need to add a total in state level - how many salespersons met their target and how many didn't.
That is, to show something like:
10 met target
5 below target
in state group total.
How can I do that?
I'm attaching an example based on my report (I can't publish the report).
Report
What I need is highlighted in yellow. For state 04 I have 3 salespersons. 2 of them met their target and 1 didn't.
=SUM(IIf(sum(Fields!OrderCount.Value)>=50, 1, 0)) & " met target"
gives me 1 met target and not 2.
edited April 1st 2020
Alan, if I understand you correctly, I need to define on which scope to calculate the sum.
This part sum(Fields!OrderCount.Value, "stateGroup")>=50 should be in the Salesperson level. so my scope is "Salesperson". The full expression is in the StateGroup total.
=SUM(IIf(sum(Fields!OrderCount.Value, "Salesperson")>=50, 1, 0)) & " met target"
But, when I try it, with either scope name, I get this error message:
The value expression for the TextBox 'A' specifies a scope that is not valid for a nested aggregate. The scope must be the same name of the scope specified by the outer aggregate or the name of a group or data region that is contained in the scope specified by the outer aggregate.
So, what am I still doing wrong?
This is off the top of my head but I think the following will work..
=SUM(IIf(sum(Fields!OrderCount.Value)>=50, 1, 0)) & " met target"
and
=SUM(IIf(sum(Fields!OrderCount.Value)<50, , 0)) & " below target"
Update based on OP remarks
If the expressions are in a different scope then you need to specify the scope.
e.g. If you States were grouped in a RowGroup called stateGroup then the expression would be something like.
=SUM(IIf(sum(Fields!OrderCount.Value, "stateGroup")>=50, 1, 0)) & " met target"
Related
I am new to SSRS and have a SUM(IIF question.
My data set contains four columns: Date, GroupID, PlanPaid, and NetworkIndicator.
Here is an example of the data set:
I am trying to SUM the [PlanPaid] amount when [NetworkIndicator] = "In Network".
However, I need this amount broken up by the [Date]. I tried accomplishing this by creating the expression:
=Sum(IIf(Fields!NetworkIndicator.Value = "In Network"
, Fields!PlanPaid.Value
, Nothing)
, "Claims_Rolling12")
But this expression returns the same amount (total) across all [Dates]. How do I break it up so that it is grouped by the correct [Date]?
Here is a photo of my Tablix and my current Groups: [Tablix and Groups]
And here is a photo of the output: [Output]
You haven't said where you want this sum to appear, so the answer here might not work. If it doesn't then edit your question to show what you expect the output to look like based on your sample data.
I'm assuming here that you want to add a new column to the report that shows "In Network total" by date.
The easiest way to do this is to add a row group that groups by date, then within this group you can use a simple expression, like the one you tried, but without specifying the scope.
=SUM(IIF(Fields!NetworkIndicator.Value = "In Network", Fields!PaidPlan.Value, Nothing))
This expression will only sum rows that are within the current scope, in this case the scope will be the row group you created to group by dates.
As IO said, if this is not helpful, edit your question and show what you expect your end result to look like, based on the sample data you supplied and then I can look at it again.
All,
I run into some problems with totals using the DSUM function.
I have a Main form and a subform (details). The subform is displayed in datasheet view inside of the main form.
The subform contains a OppL_ID (PK, autonumber), Opp_ID (FK, is multiple times present), Product, Unit, Unit price.
Now I want to calculate the total revenue per Opp_ID on the main form. In the main form an Opp_ID selected, several rows with products are shown in the subform connected with that Opp_ID. If the user enters data in the datasheet view, the revenue must be calculated again directly.
I first try to get the formula working in the footer of the subform. But I cannot get the correct sum of revenue.
Now I have added in the query of the subform the Revenue: [Units]*[Unit Price]. This displays the revenue per unique line. I want the revenue per Opp_ID, so I tried the DSUM function.
What I tried:
To total the Revenue per Opp_ID I used the formula: DSUM([Units]*[Unit Price];"Qry_lines";"[Opp_ID]=" & [Opp_ID])
I also tried the control names instead: DSUM([txt_Units]*[txt_Unit Price];"Qry_lines";"[Opp_ID]=" & [Opp_ID])
I aslo tried to reference the Revenue field: DSUM([Revenue];"Qry_lines";"[Opp_ID]=" & [Opp_ID])
All of the formulas end in the result:
Example:
Opp_ID 51 consists of two lines with products A and B, Line of product A = Units 1 Unit price 20. Line of product B = Units 2 unit price 30.
Result: If I stand on A, the total revenue is 40 and on the line of product B 120.
I would expect only one figure:
1 * 20 + 2 * 30 = 80
It looks like it calculated revenue times the number of rows? What am I doing wrong?
I also tried to create a sum query and to reference this, for example:
Select Qry_lines.Opp_ID, Sum(Qry_lines.Revenue) as SumofRevenue FROM Qry_lines Group by Qry_lines.Opp_ID.
Now I get the correct figure per Opp_ID. Only I cannot reference this in my form? Perhaps with a Dlookup?
I think I am close but I cannot really nail it. Please help :)
Consider:
Use DLookup() domain aggregate function expression in textbox to reference the aggregate query.
Commit record edits to table with code in control's AfterUpdate event. One way is If Me.Dirty Then Me.Dirty = False
In same event, use Refresh or Requery or Recalc command on main form.
Here I am, again with another doubt.
Here is my problem:
I have a report where I show ALL the incomes and expenses of the company for the last two days, which i managed by placing a column group grouping the columns by the date
Originally, the report contained a single matrix with both incomes and expenses fed by a dataset that points to the company cube applying the following filter expression
=IIF(Fields!Fecha.Value=Parameters!FechaHoy.Value or Fields!Fecha.Value = Parameters!DiaAnterior.Value,true,false)
FechaHoy = date sent via report parameter input
FechaAyer = date
parameter minus one day
and the filter value set to
=true
So far so good. Today, the upper management decided to split it into three matrix. One for incomes and other two for expenses (one for each expense category), so i startet with this
initial report layout
I created two new datasets for each one of the expense categories with the same filters, and now i'm here
current report layout
THE THING IS... as you can see, there is a "Total Destino" independent table where i have to add the totals of the second and third matrix in the image I added, but, as I already said I have to show the last two days, so i also have to partially add the total of each day (which are column grouped by date)
I'm pretty sured that there's also a better and more efficient way to manage what I did with the three matrices but the main issue which needs your assistance is how do i add the totals of the second and third matrices.
I already tried with
=Sum(Fields!Saldo.Value, "Informacion_Destino") + Sum(Fields!Saldo.Value, "Info_InvTesoreria")
but it adds the two days and repeat it for the two days. I also tried with ReportItems!TextBox + ReportItems!TextBox but the preview loads sends me an error message.
Thanks in advance for your time and help
Like Harry stated already out you can use for your overall total the following expression for the Tesoreria Subtotal + Destino Subtotal :
=ReportItems!TesoreriaSubtotal.Value + ReportItems!DestinoSubtotal.Value
This would give you the overall total for all days. Now if you just have to show the last two days you can add a tablix filter, like this:
'Expression
=IIF(CDate(Fields!YourDate.Value) < DateAdd("d", -2, Now()), True, False)
'Format
=Boolean
'Value
=False
After some research, I see that blending parameters is a popular topic but I haven't found a solution to this specific situation. Shortly said, I have 3 parameters from various datasets all stating the same year and I want to blend them (visually) into 1 so to eliminate this redundancy for my report's end-user.
In the "Available values" from "Parameter properties", all the values are taken from a dataset (hidden) and the "value field" is [Measures].[ParameterValue] from their corresponding hidden dataset.
When I "show hidden datasets" and go into "text mode" of each of these hiden datasets are these are the 3 MEMBER [Measures].[ParameterValue] AS :
[Time].[Financial Year].CURRENTMEMBER.UNIQUENAME
[Financial Period].[FP - Year].CURRENTMEMBER.UNIQUENAME
[Time exit].[Financial Year Exit].CURRENTMEMBER.UNIQUENAME
When you look at what value this gives, they have the following output (accordingly):
[Time].[Financial Year].&[2017]
[Financial Period].[FP - Year].[FP - Year].&[2017]
[Time exit].[Financial Year Exit].Financial Year Exit].&[2017]
A. So, in my opinion, since the "roots" of each [Year] parameter value are different I need to create a dataset or a member within each of these hidden datasets that replaces this [2017]. Is that "doable" and, if yes, any guidance on how?
B. If not, another outcome would be acceptable as well: the end user would need to generate mostly current year and current year-1. To tackle this I made a Template "Year" DS with the same content as in FP - Year and added the following members:
Member [Measures].[Last Year] as 'YEAR(NOW())-1'
Member [Measures].[Current Year] as 'YEAR(NOW())'
I inserted them into SELECT and previewed, it displays 2 new columns with 2017 and 2016. Then I went and changed in that PF-Year parameter's DS, value and label and I get an error. Any suggestions?
Any suggestions on this?
EDIT1: I have tackled B. and found a solution to it, I simply created the following 2 Default values for each parameter:
Current year: ="[Time].[Financial Year].&[" + CStr(Year(Now())) + "]"
Last year: ="[Time].[Financial Year].&[" + CStr(Year(Now())-1) + "]"
However, even though with this result I presume it will minimize the number of actions for the end-user, I would still prefer having 1 parameter showing instead of 3...
EDIT2 & partial solution I found another solution for A., it's not exactly what I wanted but it kind of gets the job done.
Created a new Year parameter with 2 available values: [CurrentYear] and [LastYear]
For each of the default values of each other parameter, I swaped the 2017 and 2016 values for CStr(Parameters!Year.Value(0)) and for CStr(Parameters!Year.Value(1)) accordingly. Example: ="[Year exit].[Financial Year exit].&[" + CStr(Parameters!Year.Value(0)) + "]".
In the options of each parameter, I set them as "Hidden" expect for my new Year parameter.
Now, I have 1 Year parameter with a dropdown list displaying Current Year and Last Year.
Even though this alleviates the issue, is there anyway to have a similar outcome but with the drop down menu displaying the actual years? i.e. it would be dynamic so in years to come, there would be 2018, 2019, etc. that would pop up? This way the end user would be able to compare not only current and past year but any 2 years?
Thanks to all!
EDIT3 Here is a screen shot of where I am at, at this point:
EDIT4
I have arrived to a fix: since I know that the end-users will only be comparing 2 years at a time (so 2 default values per parameter), I left hidden 2 parameters out of 3 and for the 2 hidden, I changed their default values.
So, I kept #[Financial Year] as my main parameter and the others have the following default values:
#[FP - Year]:
="[Financial Period].[FP - Year].[FP - Year].&[" + CStr(Parameters!Financial Year(0)) + "]"
="[Financial Period].[FP - Year].[FP - Year].&[" + CStr(Parameters!Financial Year(1)) + "]"
#[Financial Year exit]:
="[Year exit].[Financial Year exit].&[" + CStr(Parameters!Financial Year(0)) + "]"
="[Year exit].[Financial Year exit].&[" + CStr(Parameters!Financial Year(1)) + "]"
And voilĂ the result:
I'd suggest two ways:
1: SSRS: add an invisible parameter (i.e. CurrentYear) and run in your MDX query the following:
StrToMember('[Time].[Financial Year].&[' +#CurrentYear + ']')
2: MDX: add a dynamic calculated members for each hierarchy:
member [Time].[Financial Year].[Current Year] as
StrToMember('[Time].[Financial Year].&[' + Format(Now(),'yyyy') + ']')
See my blog post for more details.
It is basically the same question I had in this thread:
Adding values to a Report when there is no Data in query SSRS
The only difference now is that I want to extend the same functionality to different Datasets.
Imagine this:
I have two Datasets. Dataset1, Dataset2.
Both have the same primary key, in this case:
Sales Rep
Category
Now in Dataset1 I have the following Data:
The idea in that thread was to put "0" Each time a Sales Representative Did not have all the categories, if you see for example Sales Rep on DataSet1, does not have G1,G2 Category so In those cases they have to put 0.
Thanks by the answer of the community this can be achieved by adding a Calculated Field on DataSet1:
=Fields!SalesRep.Value & "-" & Fields!Category.Value
So that will give you for example 11-G1 for the 1st Row. and the expression for each Row (For each category) will be:
=iif(IsNothing(lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7")),0,
lookup(Fields!SalesRep.Value & "-" & ReportItems!Textbox62.Value,
Fields!Another.Value,Fields!Sales.Value,"DataSet7"))
As you can see, the ReportItems!Textbox62.Value saves the value of the Category so If 11-G1 is nothing (dont exist) put "0".
The idea here is to do the same thing with DataSet2.
The tricky part is that we have to ask if 11-G1 equals 14-G1 because in DataSet2 the SalesRep does not exist for all the categories it must put "0". Both are grouped as SalesRep.