Sorting aggregate data in SSRS report - sorting

I have what seems to be fairly simple table in an SSRS report. My data query gives me a set of product names with a price column and category column. In my table, I have shown the categories as rows and the total price of all products in that category as data.
How can I sort the categories based on the largest aggregate sum of prices?
I've tried adding a sort expression to the category row group and the column group, but neither are working correctly. The sort expression is 'Sum(Product_price)'
My guess is that it's sorting based on the largest individual produce price rather than the aggregate, or something else entirely.

My recommendation would be to create a subquery in your sql statement that returns the sum.
SELECT T1.*,
(SELECT Sum(S1.YourFieldNameHere) FROM Products S1 WHERE S1.AValueToLinkWith = T1.AValueToLinkWith) AS Product_price_sort
FROM Products T1
Then use your new field in your sorting expression like any other field.
Fields!Product_price_sort.Value

Related

Tableau - different order of items when filtered vs not filtered

I have a dataset where when the category filter is set to ‘All’ the data is sorted alphabetically, which is what I want. When the category is filtered to anything other than ‘All’ (about 30 distinct categories) I want the data in the view to be sorted by a dimension: rank, where each obs has a number ranking it in order of dollar value, within each category. How can I do this? If I sort by rank, it overrides the alphabetic sorting of ‘All’ when I need each in their distinct cases. Thanks!
Tried adding ‘category’ to rows so that I could sort ‘category’ in the filter, which is the only place I need it. But this overrides the alphabetic sort when the category is default ‘all.’

SSRS Tablix Cell Calculation based on RowGroup Value

I have looked through several of the posts on SSRS tablix expressions and I can't find the answer to my particular issue.
I have a dashboard I am creating that contains summary data for various managers. They are entering monthly summary data into a single table structured like this:
Create TABLE OperationMetrics
AS
Date date
Plant char(10)
Sales float
ReturnedProduct float
The data could use some grouping so I created a table for referencing which report group these metrics go into looks like this:
Create Table OperationsReport
as
ReportType varchar(50)
MetricType varchar(50)
In this table, 'Sales' and 'ReturnedProduct' are the Metric column, while 'ExecSummary' or 'Quality' are ReportType entries. To do the join, I decided to UNPIVOT the OperationMetrics table...
Select Date, Plant, Metric, MetricType
From (Select Date, Plant, Sales, ReturnedProduct From OperationMetrics)
UNPVIOT (Metric for MetricType in (Sales, ReturnedProduct) UnPvt
and join it to the OperationsReport table so I have grouped metrics.
Select Date, Plant, Metric, Rpt.MetricReport, MetricType
FROM OpMetrics_Unpivoted OpEx
INNER JOIN OperationsReport Rpt on OpEx.MetricType = Rpt.MetricType
(I understand that elements of this is not ideal but sometimes we are not in control of our destiny.)
This does not include the whole of the tables but you get the gist. So, they have a form they fill in the OperationMetrics table. I chose SSRS to display the output.
I created a tablix with the following configuration (I can't post images due to my rep...)
Date is the only column group, grouped on 'MMM-yy'
Parent Row Group is the ReportType
Child Row Group is the MetricType
Now, my problem is that some of the metrics are calculations of other metrics. For instance, 'Returned Product (% of Sales)' is not entered by the manager because it is assumed we can simply calculate that. It would be ReturnedProduct divided by Sales.
I attempted to calculate this by using a lookup function, as below:
Switch(Fields!FriendlyName.Value="Sales",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProduct",SUM(Fields!Metric.Value),
Fields!FriendlyName.Value="ReturnedProductPercent",Lookup("ReturnedProduct",
Fields!FriendlyName.Value,Fields!Metric.Value,"MetricDataSet")/
Lookup("Sales",Fields!FriendlyName.Value,Fields!Metric.Value,
"MetricDataSet"))
This works great! For the first month... but since Lookup looks for the first match, it just posts the same value for the rest of the months after.
I attempted to use this but it got me back to where I was at the beginning since the dataset does not have the value.
Any help with this would be well received. I would like to keep the rowgroup hierarchy.
It sounds like the LookUp is working for you but you just need to include the date to find the right month. LookUp will return the first match which is why it's only working on the first month.
What you can try is concatenating the Metric Name and Date fields in the LookUp.
Lookup("Sales" & CSTR(Fields!DATE.Value), Fields!FriendlyName.Value & CSTR(Fields!DATE.Value), Fields!Metric.Value, "MetricDataSet")
Let me know if I misunderstood the issue.

Sort table in ssrs for an aggregate field

I have a column that returns me tasks to find out how many there are I do a CountDistinct (id_tarefa). I need to sort the table by this larger field for the lower value of count (), but the SSRS does not accept sorting by field that has aggregate function.
It is possible to do this sort?
Yes it's possible - but you cannot sort the table by using an aggregate function.
The trick is to sort on the Group and not the table. Row Group -> Group Properties then the Sorting tab.

Joining grouped tables

I have two different scripted data sets that I am pulling data from and aggregating (on the same key). What I want to do is to display one one line the aggregated data from both sources. The data is coming from a scripted data source (POJOs).
A simplified example is given below in which an Order has many Components, with each component being for a different customer at a different quoted price. Then when each Order is filled in different lots (or Fills) at different prices. I want to be able to produce a summary of each Order with the total Ordered and Filled quantity, and the weighted average quoted price and filled price.
An Order Component table
Order ID, Customer Num, Qty, Quoted Px
Ord01,Cust01,3,100
Ord01,Cust02,3,102
Ord02,Cust01,5,200
Ord02,Cust03,5,204
And then a Order Fullfillment table
OrderID,FillId,Qty,CostPx
Ord01,F01,4,100
Ord01,F02,2,106
Ord02,F03,2,200
Ord02,F04,8,210'
I would like to display something like this:
Order ID, Order Qty, Fill Qty, Avg Order Px, Avg Fill Px
Ord01, 6, 6, 101, 102
Ord02, 10, 10, 202, 208
I've tried using subreports and that seems to be able to get me the results but in a terrible format. The subtable headers repeat so every order gets it's own headers.
You may want to create a BIRT joined dataset between your two scripted datasets, based on a full outer join on the "order ID" column, and then use this joined dataset in your report. It should meet your needs.
I solved my problem by more or less following the following guide.
So I created a List linked to my first data source. I then added a group on Order ID so that I had one list row per Order. In the group header I added a 2x1 grid, I placed a table of the Order Components into one side of the grid and a table of Fills into the other. I had to add filters to both of these so that they only contained data for the correct OrderId. I then grouped the tables by OrderId, added my aggregation fields.
All that is left is to set the visibilty. So I set the visibility of the table details to false. In order to only show the table header once (instead of once per order) I added a Running Count aggregation to the List and set the visibiity to invisible when this aggregation was greater than 1.
Was actually quite easy in the end but took me ages to work out how to do it.

Sort Report table by totals

I have built a report with a table. It looks very much like the table in the following link (last figure, before "Next Steps").
Microsoft Tutorial: Adding grouping and totals
I have turnover values for products which are grouped by subcategories and categories and have a total for subcategories and categories. I want to sort the table by turnover (in the example it is "line total"). I can do that for the single product values in a subcategory, but not for the totals. Is that possible?
For all people interested: the row groups can be sorted by themselves (in Row Group - Group Properties). As the sort expression, one has just to choose SUM(Fields.LineTotal.Value).

Resources