SSRS operations across lines of the same dataset - Subsetting - Lookup - reporting-services

I've got the following dataset:
I need to show in SSRS two lines: One corresponding to Sales for IsControl = 0 and the other one corresponding to IsControl = 1.
However, for the line that has a control = 1 Sales will have to be divided for the its Num_Of_Customers and multiplied for the Num_of_Customers of the same week_of_day where IsControl = 0.
In other words I'm scaling sales for IsControl = 1 to IsControl = 0. In a way that I can show the two lines on a line plot.
What is the SSRS expression to do that?
Sales and Num_Of_Customers in this case are equivalent for IsControl = 0 and IsControl = 1 but they are normally different.

If I understand the question correctly, the expression below should do what you need.
=IIf(Fields!IsControl.Value = 1,
Fields!Sales.Value/Lookup(Fields!week_of_day.Value.ToString() & "0",
Fields!week_of_day.Value.ToString() & Fields!IsControl.Value.ToString(),
Fields!Num_Of_Customers.Value,
"DataSet1"),
Fields!Sales.Value*Fields!Num_Of_Customers.Value)
If IsControl is 1, lookup the number of customers where IsControl is 0 for the same date, and divide Sales by that number. Otherwise, multiply Sales by the number of customers in the same row.
If you just need Sales for the rows where IsControl is 0, use this:
=IIf(Fields!IsControl.Value = 1,
Fields!Sales.Value/Lookup(Fields!week_of_day.Value.ToString() & "0",
Fields!week_of_day.Value.ToString() & Fields!IsControl.Value.ToString(),
Fields!Num_Of_Customers.Value,
"DataSet1"),
Fields!Sales.Value)
Whatever you need, the Lookup will get you to the row where IsControl is 0. Pull the value you need and do what ever math is necessary.
Good luck!

Related

Using like operator in SSRS Expression

I have a tablix with following results.
SSRS Result
Since i am learning SSRS. i wonder how to Sum line total with respect to product name. Since product name has duplicate values but it has only M and Xl difference. If i use row group it won't total like i expected since it has M and Xl difference. I wonder how to write an expression for the total.
The desired result set
May 31 2011 S043659 Long-Sleeve Logo jerse M 3 $86.52
Long-Sleeve Logo jersey XL 1 $28.84
Total $115.36
mountain bike socks M 6 $34.20
i used this expression but giving me an error.
`IIF((Fields!Product.value = Previous(Fields!Product.value),Sum(Fields!linetotal.value))`
There's actually a few things wrong with your expression.
The IIF doesn't have a 3rd argument for the ELSE value. In this case, you'd want to use 0. So the expression would be IIF the fields match then LineTotal Else 0.
You want to have the SUM on the outside of the IIF, otherwise it will only SUM one row.
The matching without the size is trickier. I have it trim off the last 4 characters to exclude the size for a match - it may not work depending on your other Product names.
=SUM(IIF(LEFT(Fields!Product.value, LEN(Fields!Product.value) - 4) = LEFT(Previous(Fields!Product.value), LEN(Fields!Product.value) - 4), Fields!linetotal.value, 0))
The expression reads the SUM of (IF the Product matches the Previous Product then the Line Total else 0).
All this being said, it would actually be easy to crate a parent group and GROUP BY on the parent product. Unfortunately, your data uses a comma to separate one type (jersey) by size but a space in another (socks) so I don't see how to do it. If they all had a comma, I would create a Calculated Field on the dataset to use the product-line up to the comma.
=LEFT(Fields!Product.value, INSTR(Fields!Product.value, ",") - 1)
IF your Product line is either a comma or space to separate, you might be able to use this for your Calculated Field:
=LEFT(Fields!Product.value,
IIF(INSTR(Fields!Product.value, ",") > 0,
INSTR(Fields!Product.value, ",") - 1,
InStrRev(Fields!Product.value, " ") - 1) )

SSRS - How to count values in a column that is generated by an expression?

In my SSRS report, I have a column named permit_status. This column has a value generated by an expression (i.e. it comes from custom code). The permit_status value is calculated row-by-row.
The requirement is to show a sum of the different values displayed in the permit_status column, and to have this export to Excel. The values are "Approved" "Pending" etc. I just need one cell showing the total for each value.
I am able to create a footer for this report that uses Sum(...), for example:
=Sum(IIF(ReportItems!permit_status.Value = "Approved", 1, 0))
However, this only shows the sum of "Approved" values for that page of the report - not for the entire report. (And I'm missing something as it doesn't export to Excel.)
What's the best way to sum ReportItems!column_name.Value into a grand total?
In your matrix add column group based upon permit_status ( so that each column contains one available unique value) . right mouse click on left most field on your row and then select add total after, amend this field expression to count(Fields!permit_status.Value)
As I understand your question you want to count the amount of "Approved", "Pending", etc... values. There are different ways to achive this. The easyest way without changeing the structure of your tablix is a expression:
Either for one Cell:
="Approved: " & Sum(IIF(ReportItems!permit_status.Value = "Approved", 1, 0)) & " / " &
"Pending: " & Sum(IIF(ReportItems!permit_status.Value = "Pending", 1, 0))
'And so on...
Or more cells:
'Cell 1
="Approved: " & Sum(IIF(ReportItems!permit_status.Value = "Approved", 1, 0))
'Cell 2
="Pending: " & Sum(IIF(ReportItems!permit_status.Value = "Pending", 1, 0))
How about you add two Extra columns "Assigned" and "Pending"
and then for those colum set Row rule as below respectively.
IIF(ReportItems!permit_status.Value = "Approved", 1, 0)
IIF(ReportItems!permit_status.Value = "Pending", 1, 0)
Then at end of data set just add Total as described here. IT will give you desired result

How to not COUNT a value in SSRS matrix when value is NULL

I cannot make the my expression NOT count a NULL value in my SSRS matrix.
In my SSRS matrix, I have 2 columns one for AppraisalCompany and a count under the SubmittedDate column. In my report this what is happening:
Per Derrick's suggestion here is the change I made in the ColumnGroup properties for the SubmittedDate:
Here is my expression change in the ColumnGroup properties:
Unfortunately I got this error:
I'm suspicious of your Dataset, I'm not entirely sure how you're getting a null value to return 1 in the COUNT. I have been unable to reproduce your results.
Dataset Query
SELECT 'Drive In' AS AppraisalCompany, NULL AS SubmittedDate
UNION
SELECT 'Photo App - English', 'Dec-18'
Next I created a Row Group on AppraisalCompany and a Column Group on SubmittedDate.
I filtered the column group to remove the null grouping, using the expression =IsNothing(Fields!SubmittedDate.Value), operator <>, and Value true.
In the textbox in the matrix I used [Count(SubmittedDate)].
OUTUT
Appraisal Company | Dec-18
-------------------------------
Drive In | 0
Photo App - English | 1
By a Decimal (Number) datatype Nothing and 0 are the same. You can test this.
Put a tablix into your report with year from 2017 to 2019. Then put the year in a column of the tablix as a number format, then write the following expression in the detail textbox:
=CDec(IIF(CDec(Fields!Year.Value) = 2017, 0, Nothing))
After executing your report you will notice that every value in the year column is 0.
The same goes for the check. Both of these expressions will always return Yes. I basically check for 0 and the second one for for Nothing:
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = 0, "Yes", "No")
=IIF(CDec(IIF(CDec(Fields!Jahr.Value) = 2017, 0, Nothing)) = Nothing, "Yes", "No")
But remember your textbox/column has the be a number format.
So if you want to return Nothing and you display it in a number format textbox, it will show you a 0.
With this in mind it will make sense that a Count() returns the value 1 for 0 AND Nothing. So basically this will do the trick:
'Cont
=Sum(IIF(Fields!YourValue.Value = Nothing, 0, 1))

ssrs sum group totals for specific groups and subtract for specific groups

I have a report like this:
I have grouped on group name called expense type. Ideally expense type has three types, 1, 2 and 3. I have used them to sum up in TOTAL in blue line.
Now I want to add the total of totals to brown tan line,
I want ( (total of group 1 + total of group 3 ) - total of group 2 ) in the tan color total billing submitted.
Can anyone help me in writing this expression?
Use IIF() or SWITCH() to check the Category of each value before you calculate the totals.
=(Sum(IIF(Fields!ExpenseCategory.Value = "Group 1", Fields!Amount.Value, nothing))
+ Sum(IIF(Fields!ExpenseCategory.Value = "Group 3", Fields!Amount.Value, nothing)) )
/ Sum(IIF(Fields!ExpenseCategory.Value = "Group 2", Fields!Amount.Value, nothing))
You can use report items to achieve what you want
for example..
=(Reportitems!group1total.value +Reportitems!group3total.value )-Reportitems!group2total.value
The above assumes that the property name for the group boxes are group1total, group2total and group3total

DLookup: Need to be able to add to most recent entry

I have a form that is being used to create entries with different sequential fields. I'm currently using DLookup in order to do this, but I am running into some issues.
Me.txtProgramID.Value = DLookup("ProgramID", "tblMain", "Program = Forms!Form2!Combo.Value") + 1
Me.txtProgramNumber.Value = DLookup("Number", "tblMain", "Program = Forms!Form2!Combo.Value") + 1
Me.txtSequence2.Value = DLookup("Sequence2", "tblMain", "Program = Forms!Form2!Combo.Value") + 1
Me.txtSequence1.Value = DLookup("Sequence1", "tblMain", "Program = Forms!Form2!Combo.Value") + 1
There are four different values: ProgramID, ProgramNumber, Sequence1, and Sequence2. Everytime a new record is added, based on the contents of Combo, the contents of the new field should be the previous field + 1.
Lets say the contents of Combo is A and that the values for ProgramID, ProgramNumber, Sequence 1, and Sequence 2 are all 1. The new record for A should have them all as 2. The problem I'm having is that instead of DLookup finding the most recent entry, it is capturing the original, meaning that instead of having 1, 2, 3, 4, etc I have 1, 2, 2, 2.
Really what I need to know is how to make DLookup grab the most recent record in regards to the respective profiles.
You might be able to get away with DMax, but once you have more than one user, all bets are off:
Me.txtProgramID.Value = DMax("ProgramID", "tblMain", _
"Program = Forms!Form2!Combo.Value") + 1
ProgramID should probably be an autonumber, so there is no need to get the next number, it is handled autmatically. However, there is no guarantee that an autonumber is the previous number +1. I am not sure why you would have a programID and a program number.
A proper sequential number is a but more complicated: Access VBA: Find max number in column and add 1