Report Builder - Total Expressions - reporting-services

I have a report that displays the following data:
Quantity
Line Item Total/Extended Price (this is based off of a formula of rate * quantity)
Product Type (i.e. Type A, B, C, D, & Other)
At the bottom of the report, I would like to add a small three column table that takes the total quantity and price by the product type.
The table will only ever have 5 rows - row 1 = Type A, etc. Columns will be "Qty" and "Total" which should represent the sum of each based on the type.
I am struggling getting a RunningValue formula to work with a IIF statement that would filter based on type.
Here is what I have tried in cell A1 of the table (to display qty total for type a only):
=IIf(Fields!type.Value="A",RunningValue(Fields!quantity.Value, Sum, Nothing)

To achieve this it would be best to use a Matrix, as follows
Create a matrix and set the row grouping to be your Type Field.
Right click the column header and select Insert Column – Inside Group Left to give you two columns to display the Quantity and Total values.
In the header you can right click the area and selected Insert -> Rectangle, then added two text boxes to give the column headings (in blue)
In the left Dataset set the expression to be
=sum(CInt(Fields!Qty.Value))
To sum all the values for this Type together (Note this assumes the are integers, you can use CDbl for doubles for example)
Do the same for the Totals text box as well (note I have set the expression to return a currency as well – Right Cick -> Palaceholder Properties -> Number -> Currency)
This matrix looks as follows in design mode
And like this when rendered (note the source data I am using to generate this is also shown)
Is this the sort of output you required? Let me know if I can help further.

Related

Top N by Count of Dimension Tableau

I am a bit new to Tableau.
I have two columns: DATE and Car Model
I want to create bar graphs for the Top 5 (Count of Car Model) each individual year on the same sheet.
When I select the Top N filter, it selects the overall top 5 models and displays counts for each such model.
However, each year has a different Top 5. I want to be able to get the top for that particular year only.
Can anyone help me with it?
This you can do through function INDEX. Do these steps (I am replicating your problem on sample superstore as you haven't given any data)
I built a view/viz with order date & customer name rows shelf and sum(sales) on columns shelf.
create a calculated field named say INDEX with formula INDEX()
drag this INDEx field to DETAILS on Marks card
right click, edit table calculation and set the following options
-- specific dimensions (check both fields drag to adjust date field prior to second nested field)
-- At the level (select second field name - customer name in my case)
-- restarting at every (select first date field , order date in my case)
-- sort order - CUSTOM - select Sales(Measure) with descending and aggregation as your measure (sum in my case). A screenshot is attached for reference
ctrl + drag INDEX field to Filter and select 1 to 5.
Your desired view is ready

How do I compare all rows in a columns incrementally but also group them at the same time in access?

This is the table that I would like to compare the values within the row groups incrementally however I would not like to compare rows amongst groups as it would come with negative values.
How do I achieve this on the same table? I am unfamiliar with subqueries
It sounds like what you need is a Calculated Field added as a third column to your table.
Instructions:
Select the drop down menu next to "Click to Add" to create a new column.
From the choices available select Caluculated Field and then Number.
The Expression Builder will open.
All you need to do from there is select the column you want to use as your primary number (in your case Number) from the Expression Categories, insert a minus sign, then select the number you want to subtract from the first number (in your case Group), again in the Expression Categories.
Name the column you created whatever you would like.

SSRS: Group by matching a pattern

How can I group by based on a pattern in column to calculate the total?
My table has the following columns: CustomerAccount (char30), AccountDesc varchar(200), AccountAmount1 (decimal), AccountAmount2,....., AccountAmount5.
The CustomerAccount is in this format: xxx.xxxx.xxxxx.
Some of the values are:
How do I group the data so any value like xxx.xxxx.31xxx, xxx.xxxx.32xxx, etc is grouped together so I can calculate the AccountAmount like the image below in SSRS report? The highlighted part ranges from 30 to 39:
I am not sure if it would be easier to do it in SQL query, but not sure how.
If your account number is always a fixed length (or more precisely, if the numbers you want to group by are always in the same position) then you can create a row group with the group expression being something like
=MID(Fields!CustomerAccount.Value, 11,2)
If you wanted to group an everything up to that point you could do
=LEFT(Fields!CustomerAccount.Value, 13)
The numbers might be out by one as I can't remember if these are zero or 1 based functions but you'll soon notice that.

Error in finding sum of a group and Conditional Summing in SSRS Reports

I have an SSRS Report, in the database there is a column by name Total_running_hours.
There are more than one record for a single Cycle_number like more than 1 row with same Cycle_number but different Block_numbers and the value in Total_running_hours field will be same for all the rows with same Cycle_number. Eg. 1 Cycle number with 4 diff block_numbers contain same Total_running_hours for all 4 rows.
Now the problem is, in the group footer if I put this field then it will show the Total_running_hours value only once which is correct, but my final requirement is,
I need to get the sum of this field in the Report footer which need to display the sum group wise. No matter how many rows are there for a single Cycle_number it has to take only once and display the result.
I tried in different ways like
=sum(ReportItems!textbox204.Value) // name of text box in Group footer
Error: Report item expressions can only refer to other report items
within the same grouping scope or a containing grouping scope.
=sum(Fields!total_running_hours.Value,Group_name)
Error: The scope parameter must be set to a string constant that is
equal to either the name of a containing group, the name of a
containing data region, or the name of a data set.
Can any one please help me in getting the sum Group wise
Thank you in advance.
I found solution for this Problem.
We cannot simply sum the Total_Running_hours value as this would give us duplicates and the incorrect answer. We cannot sum the reporting services group as it goes out of scope
There is no SUM DISTINCT available in Reporting Services 2005 so we can't get the distinct value that way.
Since the query may not return a particular Cycle_Number Type we cannot use that as a filter.
The solution found was to add a column of the row number within a windowed set partitioned by the Cycle_Number like this
ROW_NUMBER() OVER (PARTITION BY Cycle_Number ORDER BY Cycle_Number ) AS 'RowNumber'
Then in the reports’ footer total column we put an expression that only takes the first row’s value to sum and converts all other rows to zero in that windowed set.
=SUM(IIF(Fields!RowNumber.Value=1,Fields!Total_Running_hours.Value,0))
After using this if u found any error in textbox like #Error
Then try this
=SUM(IIF(Fields!RowNumber.Value=1,CDbl(Fields!Total_Running_hours.Value),CDbl(0.0)))

Create Sum of calculated rows in Microsoft Reporting Services

This seems like it should be simple but I can't find anything yet. In Reporting Services I have a table with up to 6 rows that all have calculated values and dynamic visibility. I would like to sum these rows. Basically I have a number of invoice items and want to make a total. I can't change anything on the DB side since my stored procedures are used elsewhere in the system. Each row pulls data from a different dataset as well, so I can't do a sum of the dataset. Can I sum all the rows with a table footer? Similarly to totaling a number of rows in Excel? It seems very redundant to put my visibility expression from each row into my footer row to calculate the sum.
A few ways you could achieve this:
1. Do the calculation in the SQL and sum that field, like so:
SELECT Quantity, Amount, Quantity * Amount As TotalAmount FROM MyTable
Then just use the TotalAmount field in your Detail row and sum it in the footer.
2. Create a second Dataset that calculates the total for you and use that in your footer instead of a sum:
=Sum(Fields!TotalAmount.Value, "MyTotalingDataset")
3. Do it using custom code. Right-click on the Layout space choose Properties and click on the Code tab. Put in the following code:
Public Dim TotalAmount As Double = 0
Public Function CalculateRowTotal(ThisValue As Double, ThatValue As Double) As Double
TotalAmount = TotalAmount + (ThisValue * ThatValue)
Return ThisValue * ThatValue
End Function
On the Detail band, make the column where you sum the field have this expression:
=Code.CalculateRowTotal(Fields!Quantity.Value, Fields!Amount.Value)
This will execute the code above and do your calculation plus calculate the total sum in the process.
The Footer band displays the total sum so the column has the expression:
=Code.TotalAmount
And you're done. Just be careful because you aren't guaranteed the order in which your code will execute and for some reports it will execute the footer first (for example, if you use the Sum of the rows in the Detail band) which would make the total zero as the Detail band calculations haven't happened yet, but for the general case this should work.
You could change the db as follows.
Did you know you can get aggregated results in SQL without aggregating the data?
Just add an extra column to the dataset as follows:
,SUM(OrderQty) OVER(PARTITION BY SalesOrderID) AS 'Total'
In the above sample:
OrderQty is the value you wish to sum
SalerOrderID is the equivalent of 'GROUP BY'
You can use the same technique with COUNT, AVG and so on
More information here
http://msdn.microsoft.com/en-us/library/ms189461(SQL.90).aspx
In case you have a problem with the execution order, add a text box below of the table and display TotalAmount in this box.