Can Tablix Row Total only refer to last X groups? - reporting-services

I have a report in a tablix with 1 to x column groups. In the totals for each row, is it possible to refer to only say the last 2 groups? The requirement is to add a column that shows the most recent % change between the last 2 groups.
Jan Feb Mar |Total Recent % Change
5 10 5 20 50%
1 3 6 10 200%

I ended up using the technique I learned in this post: Creating conditional total rows in SSRS
Basically, I added another field with the ranking/order of the Groups in descending order (so that the most recent group is #1).
Example of the expression: (Note that I have custom code to do the divide so that I don't get divide by zero errors.)
=code.divide(sum(iif(fields!Last_ORDER.Value=1,fields!Num_Apps_Submitted.Value,0)),sum(iif(fields!Last_ORDER.Value=2,fields!Num_Apps_Submitted.Value,0)))

Related

How to sum only one of repeated values from joined data in RDLC

I'm not sure if SSRS is dumb, or I am (I'm leaning towards both).
I have a dataset that (as a result of joins etc) has some columns with the same values duplicated across every row (fairly standard database stuff):
rid cnt bid flg1 flg2
-------------------------------
4 2882 1 17 3
5 2784 1 17 3
6 1293 1 17 3
18 9288 2 4 9
20 762 2 4 9
Reporting based on cnt is straightforward enough. I can also make a tablix that shows the following:
bid flg1 flg2
------------------
1 17 3
2 4 9
(Where the tablix is grouped by Fields!bid.Value and the columns are just Fields!flg1.Value and Fields!flg2.Value respectively.)
What I can't figure out is how to display the sum of these values -- specifically I want to show that the sum of flg1 is 21 and the sum of flg2 is 12 -- not the sum of every row in the dataset (counting each value more than once).
(Note that I'm not looking for a sum of distinct values, as they may not be unique. I want a sum of one value from each bid group, because it's from a table join so they will always have the same value.)
If possible, I'd also like to be able to do a similar calculation at the top level of the report (not in any tablix); although I'd settle for hiding the detail row if that's the only way.
Obviously, Sum(Fields!flg1.Value) isn't the answer, as this either returns 51 (if on the first row inside the group) or 59 (if outside it).
I also tried Sum(Fields!flg1.Value, "bid") but this wasn't considered a valid scope.
I also tried Sum(First(Fields!flg1.Value, "bid")) but apparently you're not allowed to sum first values for some weird reason (and may have had the same scope problem anyway).
Using Sum(Max(Fields!flg1.Value, "bid")) does work, but feels wrong. Is there a better way to do this?
(Related: is there a good way to save the result of that calculation so that I can later also show a Sum of those totals without an even hairier expression?)
There are two basic ways to do this.
Do what you have already done (Sum(Max(Fields!flg1.Value, "bid")))
Sum the rendered values. To do this check the name of the cell containing the data you want (check it's properties) and then use something like =SUM(ReportItems!flg1.Value) where flg1 is the name of the textbox, which is not necessarily always the same name as the field.

How to display only unique child items and their count

I have an ssrs report with dataset that has two fields. I grouped on field 1 and then I grouped on field 2 and now I want to just show the count of each unique items within the child group.
here is what Dataset looks like
Route Driver
A Adam
A Adam
A John
B Adam
A John
and so on
Here is what I'm trying to make my report look like
Route Driver Count
A
Adam Count of number of times Adam appears in this child group.
John Count of John
Total total for all
B
Adam 25
Mike 5
Total total
C
Josh 10
and so on
However, here it is what it looks like at the moment.
Route Driver Count
A
Adam count
count
count
count
continues till the number of times Adam appears
B
Adam 25
25
25
25
continues 25 times
Mike 5
continues 5 times
C
Josh 10
continues 10 times
here is my design view
Any suggestions on how to do this? I'm open to modifying my dataset too.
Insert a matrix, add route and driver as row groups. In the right most column enter the expression: =count(Fields!Driver.Value)
#Caesar Tex, to add Drivers total for each route as a header:
In your table you should have two levels of grouping - on Route and then on Driver - and no Detail row. The Route group has a header for the row title and a footer for the subtotal and the Driver group can just have the footer row, no need for a header.
Then just have your Count expression on each of the group footers.

Average of MS SSRS Tablix group totals

I have a SQL Server Report Builder tablix report that evaluates sales activity over time.
Rows by company, columns are grouped by date. Something like this:
2015 2016 2017
Company1 10 12 1
Company2 6 5 0
Company3 8 10 7
(The report also expands columns into months)
I would like to add a column, or color a background, calculated based on the average of each year's totals. For example, Company1 averages 7.6/year if I include 2017. I would like to be able to say that 2015 was 131% of average, 2016 was 157% of average, and 2017 is 13% of average. Bonus points if I can exclude the current year from the average.
The result might look something like this:
2015 2016 2017
Company1 10 (131%) 12 (157%) 1 (7.6%)
Company2 6 (%%) 5 (%%) 0 (%%)
Company3 8 (%%) 10 (%%) 7 (%%)
Since the source data has one sale per row, and the tablix is what's creating the grouped count by date, I can't seem to just run an average, which just gives me "1", due to the fact that I'm counting on a count column. The source data looks something like this:
CompanyName Date SalesRep Amt Count
Company1, 1/1/2015, salesrepname, 50000, 1
Company1, 2/1/2015, salesrepname, 20000, 1
Company1, 3/1/2015, salesrepname, 50000, 1
Company1, 4/1/2015, salesrepname, 10000, 1
Company1, 5/1/2015, salesrepname, 5000, 1
...
How do I go about getting the average of each year?
If you were just grouping on Company and Year you could override the scope of your aggregates with a group name. However, SSRS doesn't have a way to specify combinations of groups. So in your case you will need to make those sub-calculations available another way. It is usually best to do that in the SQL. You can either add a subquery to your existing query (preferred) or add an additional dataset. If you use a separate dataset you'll also have to match up the values with a Lookup function.
If you try to come up with an elaborate workaround like custom code or referencing textboxes it is going to become difficult to maintain and will be very inefficient.
wouldn't a formula like this work?
=sum(Fields!count.Value)/
(sum(Fields!count.Value,"Year")/countdistinct(Fields!CompanyName.Value,"Year"))
assuming your column group name is Year.

Summing Values in Visible Rows Only

I have a report with one group of which the visibility is toggled based on if the [total] is greater than 5. I want to make another row, that adds up only the visible information from each column. The first column is the owner name, The 3rd column [total] gets divided by the second column to get the 4th [avg] column. Right now it's counting everything, including the hidden rows.
Also, columns 2-4 are calculated based on expressions
Example of what I want it to look like
Owner Count Total AVG
Bob 3 12 4
Jane 1 9 9
Marcos 2 24 12
TOTAL: 6 45 7.5
I also need to count the visible Owners total, and divide that by the total amount of active owners, which I pull from a second dataset.
Example if we had 12 owners total
Total listed owners: 3
% of owners: 25%
For the total displayed owners, just SUM on the expression you use to hide the row:
=SUM(IIF(Fields!Total.Value > 5, 1, 0))
then to get the percent, divide this by the COUNT of the total rows, including the hidden ones (which you already have).

SSRS tablix split report into two sets of columns

I have a report that lists some basic data about a company for all (possibly) 52 weeks of the year. The report takes in parameters of year and UptoWeek. So for example i can put in 2013 and 31 and it will spit out all the values for year 2013 up to week 31. Right now it looks like:
Week Dollars PY Dollars Change
1 5 4 1
2 20 25 -5
...
52
I want it to split into two sets of columns at the halfway point, so the left side is 1-25 and the right side is 26-52 like so
Week Dollars PY Dollars Change Week Dollars PY Dollars Change
1 5 4 1 26
2 20 25 -5 27
... ...
25 52
Is this possible in tablix?
The one thing I was thinking was to just copy the tablix next to itself and hide rows higher than 25 on the left, and lower than 26 on the right. I'm just not sure if that's the best way to handle this...
You could set up a column group based on an expression like:
=IIf(Fields!Week.Value <= 26, 1, 0)
Note that this is set to 26, as 26 really should be on the left side, I think.
Your row group expression will need to be something like:
=(Fields!Week.Value - 1) Mod 26
So say I have data like this:
(snip)
And a tablix like this, grouped as above:
With the above grouping, this works for me:
(snip)
This will split your data into two groups based and week and as such will meet your requirements. Since you're only interested in two groups and have a ready-made row number in Week, you can keep the expression simple.
Side-by-side tablixes would most likely be fine, too, but SSRS is notoriously temperamental with adjacent objects. Using grouping as above keeps this as one item at the designer level.