How to sort a report by a calculated field - reporting-services

I have a simple report made with FetchXml that shows something like this:
EMPLOYEE NAME AUTH TOTAL DRAFT TOTAL
new_UserName Exp1* Exp2*
*Exp1:
=FormatCurrency(Sum(Fields!lead1_new_totalauthorizedamountValue.Value))
*Exp2:
=FormatCurrency(Sum(Fields!lead1_new_totalfeescollectedValue.Value)- Sum(Fields!lead1_web_totalrefundamountValue.Value))
Here is the issue: I can't realize how sort the whole table by Draft Total or by Auth Total.

For each group, go to properties, and in sorting enter the expressions you mention.
For the detail, go to properties and in sorting use the same expressions without the aggregation (SUM)

Related

SSRS - add percentage of total?

I am just starting out in SSRS and have a dataset that looks like the below.
I have built this in a matrix table like so
I want to show what percentage each of the rows total is of the grand total, so for the attached image I would want to show what percentage 35 (counselling calls) is of 47 (total) and what percentage Legal calls (12) is of total (47)
I have tried =Fields!Calls.Value/sum(Fields!Calls.Value) but that just gives me 100% for both?
Would appreciate any help
You need to specify the scope of your SUM() expressions.
I'll briefly explain how scopes work and then get to the answer.
SSRS always evaluates an expression based on it's scope which is usually defined by the physical location of the expression within table/matrix. As you can see from your design all 4 textboxes show the same expression, [SUM(Calls}] which in fact is actually =SUM(Fields!Calls.Value). However they give different results because the scope of each is different. The first is in the category rowgroup and the month column group for example, the second one is in the category row group but in the total month group, and so on...
OK, now to the answer !
Assumming
your rowgroup is called 'CategoryGroup` (you will see the name in the rowgroup panel under the main designer)
your dataset is called DataSet1
You expression should be
=SUM(Fields!Calls.Value, "CategoryGroup") / SUM(Fields!Calls.Value, "DataSet1")
This basically reads..
Take the sum of the call column for all rows that are within the current CategoryRowgroup and divide by the sum of the call column across the whole dataset.
Notes
The scope names must be enclosed in quote and are case sensitive
The scope names must match either a row or column group, or a dataset name exactly.
the , "CategoryGroup" scope argument can probably be omitted as this should be the scope of the textbox anyway.

Conditional Aggregate Lookup - SSRS

I have a report with two datasets to summarise the number and value of incomplete orders by status. I have a "Back Order" column, which is using the 'Lookup' function to refer to a second database, based on a whether the Fields!IsBackorder.Value returns true. This works at line level, but I've run into issues at the aggregate level.
For the total count of orders, this forumula works:
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",1,0))
However, for the total value of orders ("Fields!NetValue.Value"), this returns '#Error'
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",Fields!NetValue.Value,0))
I've tried custom aggregate functions but I haven't found any that work. I'm not sure how I'm getting this error.
Any suggestions would be really helpful.
Thanks,
Report Screenshot
The syntax looks perfectly fine , also the lookup looks good , can you please check on the below things in your DataSet:
Is Fields!NetValue.Value in scope of the current DataSet.
Are we using the correct data type for Fields!NetValue.Value(Something which is aggregatable , like int , decimal etc.)

SSRS standalone formulas

I have been working on this for days without being able to solve yet. It's probably simple if you know what you're doing. I'm simply trying to make a standalone formula that is not in a tablix or anything, it's just in a textbox.
Here is an example of my Dataset called Dataset1:
What I am trying to get is a sum of the Actual Cost when the Category is Labor from Dataset1. My current expression is:
=Sum(iif(Fields!Category.Value="Labor", Fields!ActualCost.Value, 0), "Dataset1")
I refer to Dataset1 as my scope because otherwise, I get an error about using an aggregate expression without a scope.
The report runs but shows #Error in the textbox that has my expression in it. When I replace Fields!ActualCost.Value with a 1, I get the answer, 5, which is the correct number of rows with Labor as the Category. But it won't let me sum the numbers in the ActualCost column where Category is Labor.
Any ideas as to what I'm doing wrong? I feel like it's something to do with aggregating, but I'm not sure. Thanks!
It may have to do with the datatype of fields!ActualCost.Value. If that field is a decimal (regardless of how you have it formatted), try using cdec(0) instead of just 0 in your expression.

Aggregate function in group header?

I have a really simple recordset by the name of qryUserFiles:
string: [UserID], [ftype]; Long: [fsize]
(records are file-information details of each file in each users' userfolder on the file-server)
I have created a report which lists the sum of [fsize] for each [UserID] by grouping on [UserID] and putting =Sum([fsize]) in a textbox in the header of the group. So far so good. So that shows me the total size of that user's user-share on the fileserver. (Helpful with respect to both convincing the users to clean up their stuff, and convincing the executives that we need to buy more storage!)
Now the headbanging part.
I want to add, in that same header, various textboxes containing the sum of the [fsize] for various values of [ftype]. So, for example, I'd want the sum of [fsize] for files where ftype="jpg" for each UserID. (And then another sum of [fsize] for files where ftype="mov" for each UserID, and so on for various 'problematic' file-types!)
I tried putting a
Dsum("fsize","qryUserFiles","ftype='jpg'")
in the group header, but, as expected, it is looking at the entirety of the 'qryUserFiles' recordset, and giving me the domain-total of size for jpg, not the this-user-total of size for jpg.
I considered trying to add something to the 'where' clause of the dsum function that would include 'this' user as criteria, but how would I refer to 'this' userID, with respect to the grouping-pointer?
Or is there a way easier way to do what I want without going nuts!? Would this be easier in another query? I feel like there's a simple, obvious answer just out of reach!
(I'm hoping to avoid brute-force VBA code to step through the table record by record, and calculate the stats with Dsum and add them to a new table. But if that's how to do this....)
I think - judging from what I read - you just need to let the report do its stuff. You can group on user and ftype - including the totals in the details and the totals in the Group Footer
You definitely should not use a DSum formula

Sum function in Report Builder 3.0

I am creating a report that will sum up all subtotal per MaterialNo/Color/Quality/Size.
Here's my sample report:
Computation will be GrandTotal = sum(Subtotal)
I am using =Sum(Fields!TOTAL_CTN.Value) but the result is 12.
Is there a way to compute using like =sum(subtotal_TextBoxName)?
I'm still not 100% sure of your underlying data and business logic, but here's one approach that might help.
I'm working off the following sample data:
Based on what your description above, it sounds like you have something similar to:
Which gives results:
It seems that you don't actually want to Sum TOTAL_CTN, rather this should be the same for every MaterialNo with the Sum only applied in the Grand Total.
As such you can change the Sub Total aggregation to Max and, since you're using Report Builder 3.0, you can then take the Sum of the group level aggregation values. The report will look like this:
Where the Grand Total expression is:
=Sum(Max(Fields!TOTAL_CTN.Value, "MaterialNoMax"))
In this expression MaterialNoMax refers to the name of the Row Group (based on MaterialNo in my example).
This gives your desired results:
The key here is thinking about what aggregation gets applied at each level and how these roll up to the end total.