With SSRS how can I modify this table so the last "Line Amount" value with a repeated "Invoice Number" gets modified with the diference between "LineAmount" total and "Invoice Amount Total".
In the example, the SUM of all Line Amount values is 1574,47
I want the last value (22,77) to be 439,54, which is
Invoice Amount total - SUM(Line Amount)
2014,01 - 1574,47
And this should be done with evert block that had a repeated "Invoice Number".
Is this possible?
If there's a way to do it directly with SQL Server (which I think its even more complicated) would be ok too.
If you set up your tablix with a row group grouping on the Invoice Number, you can add a "total" row before or after the individual line item entries. You can do this by right clicking on the row group, then Add Total, then select before or after (in your case, you would want after). In the new row, you can then create an expression in the column where you would like to see the difference.
You wouldn't be able to have this replace the last row (at least not to my knowledge), so you would still have 22,77 showing. But it should get you closer to what you're looking for.
I'm not sure exactly how your dataset is structured, so your exact expression for the difference might be slightly different than this example. If the Invoice Amount is only contained on one row for that invoice number, then your expression would just look something like this:
=SUM(Fields!InvoiceAmount.Value) - SUM(Fields!LineAmount.Value)
Related
I am using a pivot table to summarize our status of completion of a project. The first value of the pivot table gives me a count of the entries in the spreadsheet column that have a value greater than 0. The next value of the pivot table gives me a count of the total estimated quantities from the spreadsheet. The third value gives me the sum of the entries from the same column of the spreadsheet that the first value uses in the pivot table. The final value of the pivot table is a sum of the total estimated quantities from the same column from the spreadsheet the second values uses for the pivot table.
My current working formula will only evaluate the SUM columns in the pivot table and is the following:
=iferror('Quantities Complete'/'Total Est Quantities',0)
This gives me a percent complete based on the SUM of those two columns from the spreadsheet. These values can differ because the first is a real value and the second is an estimated value. What I want is the below formula which I will put how the data is summarized in parenthesis for simplicity of understanding.
=if('Quantities Complete'(COUNT)='Total Est Quantities'(COUNT),1,iferror('Quantities Complete'(SUM)/'Total Est Quantities'(SUM),0))
This formula would allow me to evaluate if the count of complete items matches the total estimated items, if so the calculated field value is 100% regardless of actual sum values. Otherwise, it gives a percent complete based on sum value which is more accurate because each item can have vastly different values.
How can I refer to the 2 different uses of the columns in a calculated field formula?
I have tried the renaming the column headers to 'Items Complete' and 'Item Values' but the formula does not accept those and gave a parse error. I have tried using the "COUNTA of" or "SUM of" prefix for the column fields. I also tried typing the name as shown when I hover over the value field in the edit window which I tried in these methods: 'Quantities Complete' (Items Complete) and 'Quantities Complete (Items Complete)'. All of these yielded a parse error. I can't share my spreadsheet due to confidentiality requirements, but all I need to know is how to refer to the two different column headers that have the same name from what I can tell.
I have a report, that shows the individual sales commission for each employee.
The expression for the Sales Commission is:
=Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value
Now I want to add a total for this field. If I just right click the cell and click on Add Total, it works but gives out the wrong total.
If I try to sum the field like this:
=Sum(Reportitems!GO_Prov.Value)
I get the error:
The Value expression for the textrun 'Textbox93.Paragraphs[0].TextRuns[0]' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers.
Is there a workaround to sum the aggregated field of this tablix? Maybe with a code?
Thanks in advance.
Update1:
Unfortunately i don't know how to write custom codes. But I found this code:
Public Total_lookup_Sum As Integer = 0
Public Function Lookup_Sum(ByVal value As Integer) As Integer
Total_lookup_Sum = Total_lookup_Sum + value
Return value
End Function
The expression i used for the Sales Commission is now:
=Code.Lookup_Sum((Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value))
And the expression for the field where i would like to get the sum is:
=Code.Total_lookup_Sum
Now i get the error:
There is an error on line 0 of custom code: [BC30205] End of
statement expected.
Is there a way to solve this?
Scenarios like these can be tricky in SSRS. From your description (even though the screenshot doesn't really show everything), I'm guessing that you've got rows grouped by salesperson. In your column that's calculating the commission, you've got a sum of "Total_commission", but you've just got the "Individual_Factor" value not aggregated. Again, having a guess, but each underlying row (by employee) must have the same "Individual_Factor" value (so actually using Min(Individual_Factor) would give the same result).
But then, when you try and just take the same formula (or even a derivation of the formula), and make an overall aggregate of all of the rows, how does SSRS know which "Individual_Factor" value to use? You don't want Min() or Max(), because that would just be the lowest or highest value across all of the salespeople.
Your suggestion of a workaround via code is generally the way that I approach this. You need a report variable, something like "Commission_Grand_Total", and then you need a function in the report code that accepts 1 parameter, and in the function you'll add the parameter value to the variable. The easiest thing to do is to make the parameter the return value of the function.
Then, in the field where you currently have your commission formula (on the salesperson row), the expression in that field becomes =TheFunctionYouCreate((Sum(Fields!Total_Comission.Value)*Parameters!Distribution_Factor.Value*Fields!Individual_Factor.Value))
By passing the formula to the function, you're achieving two things:
The function will take each salesperson's calculated commission and add it to your report variable
The function will output the parameter value that you passed in (since you want to display the calculated commission amount on each salesperson's row)
Lastly, to display the overall total, the expression for that field is just the report variable that holds the overall total (that has been cumulatively added to as SSRS wrote out each salesperson's record)
TIP: I sometimes do this same sort of thing, but if I don't want the row-by-row value to be shown (I just want the cumulative total to be calculated), just put the expression that calls the function in a hidden column. SSRS will still run the function as it renders each row, but obviously it's just not displaying the result of the function.
Some MS reference for report variables and code
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/built-in-collections-report-and-group-variables-references-report-builder?view=sql-server-ver15
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/add-code-to-a-report-ssrs?view=sql-server-ver15
This is untested unfortunately but...
assuming you have a rowgroup for employee called EmployeeGroup then the expression would look like this...
=SUM(
Sum(Fields!Total_Comission.Value, "EmployeeGroup")
* Parameters!Distribution_Factor.Value
* FIRST(Fields!Individual_Factor.Value, "EmployeeGroup")
)
The inner expression reads as
Sum of Total_Comission with current employee group
... multiplied by Distribution Factor
... multiplied by the first individual factor with the current employee group
The outer expression just sums all the individual employee level sums.
I have two sheets: flight control and total hours control. Link to sheets.
Flight Control:
Total Hours:
What I want: On Total Hours, Sum the Flight Time if:
Column Name(L.D.1) matches row on Line; row Pilot matches row Pilot; cell has a value of 1.
I'm using this for cell C2, and it works:
=SUMIFS('Flight Time'!B:B;'Flight Time'!A:A;B2;'Flight Time'!C:C;"1")
And it works, giving me this:
However, this isn't very practical. I have to redo the formula every time a new pilot is introduced. And if I move columns around, it stops working.
What I need: To base my conditions on a text search. Something like:
If column name in {Flight Time!C:F} matches string on {row in col Line}, and Pilot = Pilot, and cell value = 1, SUM
In other words, I need to scale this. The final product will have dozens of pilots and L.D.s, so I need to be able to move things around.
My answer is similar to player0's but it anticipates a Flight Time tab that expands infinitely sideways as well as down.
You would start a new tab and place this formula in cell A1.
=ARRAYFORMULA(QUERY(SPLIT(TRANSPOSE(TRIM(SPLIT(QUERY(TRANSPOSE(QUERY('Flight Time'!C1:1&"|"&'Flight Time'!A2:A&"|"&OFFSET('Flight Time'!C2;;;ROWS('Flight Time'!C2:C);COLUMNS('Flight Time'!C2:2))*'Flight Time'!B2:B&CHAR(10);;9^99));;9^99);CHAR(10);0;0)));"|";0;0);"select Col1,Col2, SUM(Col3) where Col3>0 group by Col1,Col2 label Col1'Line',Col2'Pilot',SUM(Col3)'Total Hours'"))
Sometimes in complicated formulas like this, it can be difficult to translate to your real sheet if you haven't placed the sample data in exactly the same layout on the sample as it is on your real sheet. If that is the case here, change the layout of the sample so that it better matches your real data, and I can try to update the formula.
use:
=ARRAYFORMULA(SPLIT(
TRANSPOSE(QUERY(TRANSPOSE(QUERY(SPLIT(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(
IF(C2:F="",,"♠"&C1:F1&"♦"&A2:A&"♣♥"&B2:B),,999^99)),,999^99), "♠")), "♥"),
"select Col1,sum(Col2) group by Col1 label sum(Col2)''")),,999^99)), "♦♣"))
I have some summary data, by year, that I am displaying in a tablix, in a pivot table fashion. The first column is the year, each row is a single year, and each column contains counts and dollar amounts from a query.
By default all of the value columns are formatted the same way. However, I need the first 4 columns formatted as a whole number (total counts) and the last 2 columns formatted as currency or 2 decimal places with commas. As shown here, my counts have .00 that I don't want shown.
Here is something that will get you going in the right direction:
=IIf(Fields!Type.Value = "Claims Filed" OR Fields!Type.Value = "Claims Approved", FormatNumber(Fields!Value.Value, 0), FormatCurrency(Fields!Value.Value, 2))
You will have to fill in for the other options, or switch these around to use the money values in the first part of the IIf since it is the shorter list. But, this should give you a good idea of how this can be done.
It is just a simple matter of conditional formatting, SSRS style.
So I am attempting to reorganize a report I put together. I had the running totals working before the redesign, but I have been pouring over this for a day and can't figure out why it is no longer functioning as I had thought.
The sum values are correct here, but it keeps accumulating them and not spreading them out over the area paths I've defined (which are populating obviously).
I have the sprint and area name linked in a hierarchy for the row groups then followed by this expression:
=RunningValue(Fields!Sev_1_Count.Value, SUM, "RowGroup")
Each column after the area name is defining a severity level of defects, just for context. The Sev_1_Count expression should take the count of all defects in this severity level then spread them across their associated area names. Which worked in the previous version... I just can't for the life of me figure why it won't work now. Thoughts?
I think the problem is that you're applying the running total to each field. It seems that wherever you're putting
RunningValue(Fields!Sev_1_Count.Value, SUM, "RowGroup")
you should just have
Fields!Sev_1_Count.Value
instead. As you need totals on both sides, you should have a matrix and the right and bottom rows of you columns should be outside the group "Iteration Name" with a value of
sum(Fields!Sev_1_Count.Value).
Not sure what I'm missing. Maybe your original dataset is set up in a way where you can't do that?
Your row groups should be grouped on name and your column groups should be grouped on severity level.
I'm not sure what you mean by your comment below Randy, but the best practice for something like this would be to have a data-set that consists of 3 fields:
"EnvironmentName", "DefectCount" and "SeverityLevel". Then in your matrix, you have the DefectCount as your Details, EnvironmentName as your RowGroup and SeverityLevel as your ColumnGroup. Then the right column and bottom row are placed outside the groups and have the value of Sum(DefectCount). Anything outside of that seems like an over-complication.
It seems like you want to use running total to add the columns for severity levels if i'm not mistaken? then you shouldn't be grouping them on rows. Instead of the "RowGroup" scope, maybe you should try None. Good luck.