SSRS Report SUM IF - reporting-services

Working on a ssrs report I ran into a problem.
In case that the Opening balance (the first row) is recorded as an Income, the Balance in the upper right corner
Should be reduced by the value shown in the "Income" cell for the Opening Balance row.
In case that the Opening Balance is recorded as Expenses the expression should stay as it is.
This is the expression for the Balance cell: =Sum(Fields!Income.Value-Fields!Expenses.Value)
Any help would be greatly appreciated :)

It looks to me like you need to take the balance, subtract the income and add the expenses from the row in your dataset that contains the description "opening balance...".
This could be achieved by using the initial balance calculation that you already have and doing a lookup to get the income/expense for the "opening balance..." line item based on the first 15 characters of the description ("Opening Balance"):
=Sum(Fields!Income.Value-Fields!Expenses.Value) - Lookup("Opening Balance", Left(Fields!Description.Value, 15), Fields!Income.Value, "DatasetName") + Lookup("Opening Balance", Left(Fields!Description.Value, 15), Fields!Expenses.Value, "DatasetName")
I'm guessing that this won't work out of the box and that you may have to test for nothing or COALESCE your database values and/or cast your fields to get this to work. Impossible to say exactly without seeing your actual dataset.

Related

RunningValue Column

I have a report that pulls a beginning inventory value and puts it in the header of the report - "Textbox12". Then in the report there is a column that tells me how many of that particular part has shipped out or been received that day and displays that as a total (may be a negative number if we send more out that we get). How do I keep a Running Value where the first row of the report starts with the beginning balance and adds the daily change in inventory? The thing that I cant figure out is how to start with the 'Report Item Value' which represents the daily beginning balance.
My inventory report
PART No 1: beginning balance - 12345 (Textbox12)
Daily change | Total in stock
+1 | 12345+1
-2 | 12346-2
0 | 12346+0
The daily change expression is also a formula that looks at inbound and outbound columns/values in the report and totals those if that matters.
I don't think you can reference a reportitem from a tablix cell due to the order items are processed. I think the header and footer are done last so you can reference a tablix cell from the header but not the other way around.
You don't say how you get the opening balance but you should be able to copy the expression from Tetxbox12 and use that plus the RunningValue() of the DailyChange column.
So you would end up with something like this
=MyTextBox12Expressionhere
+
RunningValue(Fields!DailyChange.Value, SUM, "myDataSetName")
If this does not help, show a sample of data, the structure of your dataset and the expression in Textbox12 and I can revise the answer.

Calculate difference between multiple group columns in SSRS Report

First post in stackoverflow - so forgive me if I don't get this right. I have an SSRS report with a matrix which groups Quantity, Total Spend and Average Cost by part number for each year. Part Number and description down the left and the the years along the top. I want to add a delta column in each year after the first year which shows the change in price from the previous year. I have seen examples of how to get the difference between first and last year - but not the difference between each year and the previous one. I have hidden the delta column for the first year - no would love some guidance on how to calculate the difference in cost.
So from the image below the first row in the delta column under FY2019 would show -€0.01 as price has reduced from 0.59 to 0.58.
You haven't explained how if Avg. Cost is calculated in your report but I'm assumming it's just something like =SUM(Fields!Spend.Value) / SUM(Fields!Qty.Value)
You've not shown your report design so I can't tell what your row/column groups are called but I'll assume you have rowgroup by Part and one by Year. Let's assume your column group name is PeriodID so it's the same as my demo report.
In this case you can use the PREVIOUS() function to get the previous values to compare against.
I set up a similar report to demonstrate. As you can see in my case the year column is grouped using a columngroup called PeriodID
The expressions highlighted are as follows.
Price. This is just Cost/Qty =SUM(Fields!Cost.Value)/SUM(Fields!Qty.Value)
lastprice. This is just for illustration and debugging. It uses the PREVIOUS() fucntion to get the previous year's data
=Previous(Sum(Fields!Cost.Value), "PeriodID") / Previous(Sum(Fields!Qty.Value), "PeriodID")
Note that "PeriodID" is the name of the column group (case sensitive). This is scope for the previous function so it know to get data from the previous column group.
delta. This is the final output. It's just the current "Price" expression minus the "lastprice" expression.
=(Sum(Fields!Cost.Value) / Sum(Fields!Qty.Value)) - (Previous(Sum(Fields!Cost.Value), "PeriodID") / Previous(Sum(Fields!Qty.Value), "PeriodID"))
The final output looks like this (I've not hidden the column for the first column group or hidden last price, just so you can see it working). Also, if you see slight differences in the delta column compared to what you might expect, it's just down to the fact that the numbers are formatted to 2 decimals but my test data is up to 14 decimals.

get total from two different datasets into a third different tablix ssrs

Here I am, again with another doubt.
Here is my problem:
I have a report where I show ALL the incomes and expenses of the company for the last two days, which i managed by placing a column group grouping the columns by the date
Originally, the report contained a single matrix with both incomes and expenses fed by a dataset that points to the company cube applying the following filter expression
=IIF(Fields!Fecha.Value=Parameters!FechaHoy.Value or Fields!Fecha.Value = Parameters!DiaAnterior.Value,true,false)
FechaHoy = date sent via report parameter input
FechaAyer = date
parameter minus one day
and the filter value set to
=true
So far so good. Today, the upper management decided to split it into three matrix. One for incomes and other two for expenses (one for each expense category), so i startet with this
initial report layout
I created two new datasets for each one of the expense categories with the same filters, and now i'm here
current report layout
THE THING IS... as you can see, there is a "Total Destino" independent table where i have to add the totals of the second and third matrix in the image I added, but, as I already said I have to show the last two days, so i also have to partially add the total of each day (which are column grouped by date)
I'm pretty sured that there's also a better and more efficient way to manage what I did with the three matrices but the main issue which needs your assistance is how do i add the totals of the second and third matrices.
I already tried with
=Sum(Fields!Saldo.Value, "Informacion_Destino") + Sum(Fields!Saldo.Value, "Info_InvTesoreria")
but it adds the two days and repeat it for the two days. I also tried with ReportItems!TextBox + ReportItems!TextBox but the preview loads sends me an error message.
Thanks in advance for your time and help
Like Harry stated already out you can use for your overall total the following expression for the Tesoreria Subtotal + Destino Subtotal :
=ReportItems!TesoreriaSubtotal.Value + ReportItems!DestinoSubtotal.Value
This would give you the overall total for all days. Now if you just have to show the last two days you can add a tablix filter, like this:
'Expression
=IIF(CDate(Fields!YourDate.Value) < DateAdd("d", -2, Now()), True, False)
'Format
=Boolean
'Value
=False

SSRS Group Footer - Expression to show a certain row from dataset

This is a report for Reps showing the customers sales for the previous day and the reps budget for the customer. So in my query I've already calculated the customer total, budget etc. which I managed to put into the report. The problem I have now is that the report's display is toggled so in the group footer I need to display the customer's total as well. I can not sum the column then it will include the budget. I need to input a expression, something like this:
=Tons WHERE ItemDesc = "Customer Total"
I have tried to google for a solution but all I can find is IIF statments. Is there anyway to do this?
Example:
You should be able to use something like this...
=SUM(IIF(Fields!ItemDesc.Value = "Customer Total", Fields!Tons.Value, 0))
All we are doing here is evaluating each row's ItemDesc, if it's "Customer Total" grab the Tons value if not grab 0... then sum all the results.
Thank you Alan Schofield but that did not work. After more searching I went with the lookup:
I added a second dataset with only the totals, then in the expresion for the footer I did the following:
= Lookup (Fields!Customer.Value,
Fields!Customer.Value,
Fields!Tons.Value,
"DataSet2")
This example helped me alot: http://www.sql-datatools.com/2015/07/lookup-functions-in-ssrs.html

SSRS how to get a running total of inventory amounts IN and OUT from START DATE to END DATE?

i have a stored proc returning inventory amounts between a start and end date.
the QTY field shows on-hand inventory adjustments by date, either IN or OUT.
i have a "run balance" field that needs to show the total QTY each day. if the InOut field is 0, it's QTY in. if it's a 1, its QTY out. the values reflected in In and Out are coded that way.
EXAMPLE. if i start on 4/1/14 with 5216. then 1061 of product is made on 4/1/14 i need the run balance to take 5216 and add 1061 on the next line. the next line should read 6277 instead of 1061. then if some is shipped, take 6277 and subtract, and so on.
i tried the running value on QTY, but it just repeats the QTY. doesn't calculate anything.
=RunningValue(Fields!QTY.Value,Sum,"Details")
i tried to post an image of my report preview, but i don't have the reputation ;-)
any help would be MUCH appreciated.
EDIT: OK, i tried this code block:
= Switch(RunningValue(Iif(Fields!InOut.Value = 0, Fields!QTY.Value,0),Sum,"Details"),
RunningValue(Iif(Fields!InOut.Value = "1", Fields!RunBalance.Value - Fields!QTY.Value,0),Sum,"Details"))
and i am getting a 0 on the sum fields, and #Error on the subtraction fields. but, i think this is more the direction i need to go (i hope)....but i am still not getting it.
There are a couple of things to look at here.
First, you specify the Scope of "Details" in your RunningValue expression... By default this group will have no grouping value, i.e. each row in the dataset will be in its own group. Which means the RunningValue will only ever be applied to one row only. Change the Scope to "MyDataset" or Nothing, whatever is appropriate.
Secondly, you need to consider how the InOut field affects the RunningValue.
I have created a simple Dataset:
And a simple table:
The Balance expression is:
=RunningValue(IIf(Fields!InOut.Value = 0, Fields!QTY.Value, Fields!QTY.Value * -1)
, Sum
, Nothing)
You can see this changes the Scope from your original statement, and also applies a multiplier to QTY based on InOut.
Works OK for my sample data: