Sort table in ssrs for an aggregate field - sorting

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.

Related

Sorting aggregate data in SSRS report

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

Sort fields list in Power BI desktop

I need to sort a very long list fields in Power BI that I need in a special order - not the default sort by name/number.
My dataset looks like this:
and I created another table to use for sorting:
I am stuck from here. I think I need to create a relation between the to tables and then use it to sort the field list. But I do not know where to start.
The order I have now looks like this:
Assuming you're sorting in Power Query, then:
1 Sort table SortOrder by column SortOrder:
= Table.Sort(#"Previous Step",{{"SortOrder", Order.Ascending}})
2 Sort table Data by list SortOrder[ColumnName]:
= Table.Sort(#"Previous Step",SortOrder[ColumnName])
EDIT
It seems you're actually asking how to change the order in which fields are displayed in the Fields Pane
This is currently not possible - fields are always displayed in alphabetical order.
You may vote for this feature request: https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/18355429-use-field-order-as-ordered-in-source-query
The only workaround just now would be to rename your fields so they display in your required order - eg:
01_ClmName_A
02_ClmName_C
03_ClmName_E
04_ClmName_B
05_ClmName_Q
06_ClmName_F

How to sort a Reporting Services table by an auto generated column

I have this table:
When executed, it looks like:
This table is sorted by alphabetical order. I would like to sort it by the column named "No Vencido", which is generated in runtime combining 2 dimensions of a cube (one dimension is called "Class 1", the other dimension is called "value".
How can i sort a table by an autogenerated field?
Thanks
You can sort by any sort of expression - SSRS will quite happily sort something like two fields concatenated together:
=Fields!Class1.Value & Fields!value.Value
Just be careful to make sure the sorting is applied at the appropriate level to avoid unexpected, i.e. make sure you don't have different sorting expressions in any row group or detail group if not required.
If No Vencido is the grouping expression, apply the sorting at the group level.
If you don't want to sort on an expression, you can create a calculated field for each row in the dataset with the expression =Fields!Class1.Value & Fields!value.Value and group/sort on that calculated field as required.
Edit after comment
OK, I think you need to apply a sort expression like this to the groups that apply to the Top and Otros rows:
=Sum(IIf(Fields!Clase_1.Value = "No Vencido", Fields!Monto.Value, Nothing))
This is still sorting by the total Monto for each row group, but only considering the rows where Clase_1 is No Vencido.
Once this is set up sort by A-Z or Z-A as required.

RDLC sorting on multiple columns

I want to sort an rdlc report by two or more columns.
This could happen if I have two names that are the same so then it should next be sorted by ID column.
When I navigate to textbox properties and click the interactive sort tab I can only select one column to sort by.
How to add more than one column?
EDIT: I just realised you can edit the matrix of the entire table to add multiple sort fields. I'm guessing you can also create a group and attach that to the column if needed.
I also did not find multiple columns fields for interactive sorting.
You can workaround this by specifying an expression where you concatenate columns values. Note that date field you have to format in a sort friendly way.
=Fields!MyString.Value & CDate(Fields!MyDate.Value).ToString("yyyyMMdd")
yes, you can add multiple sort fields in the tablix properties.
Aside from that, if you click on a row textbox, you can see the Interactive Sorting tab, where you can group and sort field values.
Hope this helps!

Use an Aggregate function in Sort Expression

I have a report which uses a dataset returned from a stored procedure. There are two key columns: Name and Value
I am using this dataset for two tablixes. The first is just a straightforward tablix displaying the data.
The second groups the data based on a Name column. I need to order this data based on the Sum of Value column
However I get the following error:
[rsAggregateInDataRowSortExpression] A
sort expression for the tablix
'table1' includes an aggregate
function. Aggregate functions cannot
be used in data row sort expressions.
Is there another way I can show the data grouped by name and still order it by Sum(Value)?
Instead of sorting on the tablix you need to sort against the row group. Remove the sort on the tablix and then go to the row group properties and put the same sort expression under the sorting section there, this should then work.
OK, I just had to add an extra column for the the Sum value to my query and then use that. Not ideal, but it works

Resources