SSRS: Group by matching a pattern - reporting-services

How can I group by based on a pattern in column to calculate the total?
My table has the following columns: CustomerAccount (char30), AccountDesc varchar(200), AccountAmount1 (decimal), AccountAmount2,....., AccountAmount5.
The CustomerAccount is in this format: xxx.xxxx.xxxxx.
Some of the values are:
How do I group the data so any value like xxx.xxxx.31xxx, xxx.xxxx.32xxx, etc is grouped together so I can calculate the AccountAmount like the image below in SSRS report? The highlighted part ranges from 30 to 39:
I am not sure if it would be easier to do it in SQL query, but not sure how.

If your account number is always a fixed length (or more precisely, if the numbers you want to group by are always in the same position) then you can create a row group with the group expression being something like
=MID(Fields!CustomerAccount.Value, 11,2)
If you wanted to group an everything up to that point you could do
=LEFT(Fields!CustomerAccount.Value, 13)
The numbers might be out by one as I can't remember if these are zero or 1 based functions but you'll soon notice that.

Related

How do I compare all rows in a columns incrementally but also group them at the same time in access?

This is the table that I would like to compare the values within the row groups incrementally however I would not like to compare rows amongst groups as it would come with negative values.
How do I achieve this on the same table? I am unfamiliar with subqueries
It sounds like what you need is a Calculated Field added as a third column to your table.
Instructions:
Select the drop down menu next to "Click to Add" to create a new column.
From the choices available select Caluculated Field and then Number.
The Expression Builder will open.
All you need to do from there is select the column you want to use as your primary number (in your case Number) from the Expression Categories, insert a minus sign, then select the number you want to subtract from the first number (in your case Group), again in the Expression Categories.
Name the column you created whatever you would like.

SSRS Sum Amounts with different columns based on an expression

So i am trying to sum columns based on a condition from one group to another.
The first column is the expression that counts how many Meters are in that group by company.
in the photo it shows eight by that company that have a value of meter,
Then to the right is invoice amount
What i need to do is a conditional format for the expression that says if x company has 8 meters what is the total amount for all invoices that = meter.
I have tried a few ways but unable to get the count out of the expression under the column so i know it has something to do with my condition statement and not sure wher it is going wrong any help would be appreciated
=Sum(IIf(Fields!invoiceclass.Value = "METER" and Fields!companyname.Value, Fields!invoiceamount.Value , Nothing), "AR")
Try using:
=Sum(IIf(Fields!invoiceclass.Value = "METER", Fields!invoiceamount.Value,0))
I think you don't need to specify a scope since you want the sum be calculated per instance in the company group and you are using the expression in a cell inside the Company group scope.
Let me know if this helps.

Group by column & row in one part of expression, group by column only in another part of expression

I am trying to find a way to use the Group By functionality to create a table where the numerator of a fraction is grouped both by column and row, and the denominator is grouped only by column.
Here's my existing expression:
=Round(Sum(Fields!Days_In_Step.Value)/CountDistinct(Fields!ID.Value),1, MidpointRounding.AwayFromZero)
When grouped by rows (groupName) and columns (month/year) the numerator (Sum(Fields!Days_In_Step.Value)) gives me good data, but the denominator (CountDistinct(Fields!ID.Value)) is also grouped by row (groupName) and I don't want that.
I have a SQL solution but am trying to do this entire within SSRS expressions, if possible.
edit
Sample Data:
It would look like this. The background is that these groupings are counts of days and the "all" are counts of tickets, so we are trying to see who is sitting on their tickets longer.
Here is a mock-up including a sample data set using a pivot table:
Edit 2
Here is a full sample data set:
https://docs.google.com/spreadsheets/d/1rYPMcrLNB-FZN64Fn2-y3FtnM2iQo2VMH7YTdfiVnKM/edit?usp=sharing
I need to group on month as well as year, and I do not want to see "Exclude" in the group rows, however they cannot be filtered out of the tablix without being removed from the overall population, which is required for the denominator.
Your problem is caused by the scoping of aggregate functions. When you use aggregate function they run under the scope where it is placed in the tablix by default. In your case Sum() and CountDistinct() functions are running in both row groups (Owner Group) and column group (Month Group).
Fortunately, you can specify the scope that you want your aggregate function computes the aggregation, simply add the group name in the function:
CountDistinct(Fields!ID.Value,"MonthGroup")
The whole expression is like this:
=Round(Sum(Fields!Days_In_Step.Value)/
CountDistinct(Fields!ID.Value, "MonthGroup"),1, MidpointRounding.AwayFromZero)
Replace "MonthGroup" by the actual name of your group in columns
group.
This is result using the sample data you provided:
I've used this expression to show you how it is produced:
=Sum(Fields!Days.Value) & "/"
& CountDistinct(Fields!Ticket.Value,"MonthGroup") & "=" &
Sum(Fields!Days.Value)/CountDistinct(Fields!Ticket.Value,"MonthGroup")
Note my column group is named MonthGroup.
UPDATE: Scoping multiple groups in CountDistinct function.
Firstly I am not filtering the dataset, I prefer hide the Exclude rows using the below expression in the Hidden property of the Row Visibility window:
=IIF(Fields!Group.Value="Exclude" OR Fields!Group.Value="-1",true,false)
To count distinct id grouping by Month and Year but not by Group you can create a child group below Month group as you can see below:
My group is called Group2 and I used this expression in the Group on textbox.
=Fields!End_Month.Value & "-" & Fields!End_Year.Value
It will create a group per every Month-Year combination. When you create the group it will be added as a column group so you will have to delete the row so you will be prompted if you want to delete the group and row or delete the row only. Delete only the row leaving the group.
Now the expression you have to use is
=Round(Sum(Fields!Days.Value)/CountDistinct(Fields!ID.Value, "Group2"),1,MidpointRounding.AwayFromZero)
Replace Group2 by the name of the created group in your case.
This is the whole recreation of your scenario:
Let me know if this helps.

SSRS adding a percentage column based on a specifc column category in a matrix/tablix

I have a matrix/tablix set up so there are 4 row groups going down the left-hand side and a column group called RegCompCategory:
When the report is run, the RegCompCategory column group produces 3 distinct columns based on the categories in the underlying data:
What I'd like to do is add another column before the RegCompCategory column group that will display a percentage of the "fully-marked" column against the "total" column:
I'm guessing I will need to write an expression for the fields highlighted above, but I'm not sure how to reference the RegCompCategory to identify specifically the "Fully-Marked" category of data.
Could someone give me a few pointers? Many thanks.
Try:
=Count(IIF(Fields!RegCompCategory.Value="Fully-Market",Fields!RegCompCategory.Value,Nothing))
/
Count(Fields!RegCompCategory.Value)
It will count the number of Fully-Market rows and divide by the total rows. I think that is what you are expecting.
Let me know if this helps you.

Error in finding sum of a group and Conditional Summing in SSRS Reports

I have an SSRS Report, in the database there is a column by name Total_running_hours.
There are more than one record for a single Cycle_number like more than 1 row with same Cycle_number but different Block_numbers and the value in Total_running_hours field will be same for all the rows with same Cycle_number. Eg. 1 Cycle number with 4 diff block_numbers contain same Total_running_hours for all 4 rows.
Now the problem is, in the group footer if I put this field then it will show the Total_running_hours value only once which is correct, but my final requirement is,
I need to get the sum of this field in the Report footer which need to display the sum group wise. No matter how many rows are there for a single Cycle_number it has to take only once and display the result.
I tried in different ways like
=sum(ReportItems!textbox204.Value) // name of text box in Group footer
Error: Report item expressions can only refer to other report items
within the same grouping scope or a containing grouping scope.
=sum(Fields!total_running_hours.Value,Group_name)
Error: The scope parameter must be set to a string constant that is
equal to either the name of a containing group, the name of a
containing data region, or the name of a data set.
Can any one please help me in getting the sum Group wise
Thank you in advance.
I found solution for this Problem.
We cannot simply sum the Total_Running_hours value as this would give us duplicates and the incorrect answer. We cannot sum the reporting services group as it goes out of scope
There is no SUM DISTINCT available in Reporting Services 2005 so we can't get the distinct value that way.
Since the query may not return a particular Cycle_Number Type we cannot use that as a filter.
The solution found was to add a column of the row number within a windowed set partitioned by the Cycle_Number like this
ROW_NUMBER() OVER (PARTITION BY Cycle_Number ORDER BY Cycle_Number ) AS 'RowNumber'
Then in the reports’ footer total column we put an expression that only takes the first row’s value to sum and converts all other rows to zero in that windowed set.
=SUM(IIF(Fields!RowNumber.Value=1,Fields!Total_Running_hours.Value,0))
After using this if u found any error in textbox like #Error
Then try this
=SUM(IIF(Fields!RowNumber.Value=1,CDbl(Fields!Total_Running_hours.Value),CDbl(0.0)))