i'm currently working on a ssrs report. The report contains 4 parameters, only two are relevant to the question: no. 3 and no. 4. The label of parameter no. 3 are "12 periods" up to "24 periods", but the values are 12 up to 24 as integer.
This is what the report looks like:
enter image description here
For example if i choose the value "13 periods" (or higher) for parameter no. 3, the query retrieves data for 13 periods (or higher) startet with the last month depending on parameter no. 4. So the data are included the report. Now the column "Sum Consumtion" should be only store the Sum of the last 12 periods regardless of the parameter value no. 3 not 13 periods (or higher). So the Result is 67 not 77.
Any idea how can i do this?
Thx for your support...
You can do this by using a calculated field.
Add a calculated field to your dataset. The expression would filter it to the past 12 months. So it would be something like this:
=IIf(Fields!DateColumn.Value >= DateAdd(DateInterval.Months, -12, Parameters!EndDate.Value), Fields!ColumnToSum.Value, Nothing)
Now you can reference this new field in the total column. You would simply Sum it.
Depending on your date formats, you'll probably need to adjust the date comparison logic to meet your needs. If you don't have the End Date available in the report, add that first. It can be in the query or another calculated field in the report. But the idea is that you are getting a conditional sum.
Related
I'm stuck with a problem in SSRS 2012 that maybe is very simple:
I have a matrix with a group row (employee) and a group column (last 12 months); the values are COUNT(practicesDone) - i.e. the amount of practices worked.
I want the matrix to show an extra column on the right (after all the columns of the months, and clearly outside the column group) with again the number of practices for the current month.
Is it possible to achieve that?
thank you in advance!
You can do this, it's pretty simple.
I have assumed that your dataset contains a column that has a date for each entry and that the data returned only covers 12 months so the same month would not appear for different years. If your data does have multiple years, look at the second expression below.
Right-click your month column and then to "Insert Column --> Outside Group - Right"
Now set the expression for the text box to
=COUNT(IIF(MONTH(Fields!myDateColumn.Value) = MONTH(TODAY()), 1, Nothing))
You could swap COUNT for SUM and it should do the same thing but either will work.
All we are doing here is comparing the all data in scope which, due to the placement of the text box means the scope is the entire rowgroup. Then for all that data, check if the month matches the current month, if it does set it to 1 is not set it to nothing then count/sum all results. Count conveniently ignores 'nothing'.
If you data covers more than 12 months then you can still do this but you'll have to add a bit more to handle years and months like this.
=COUNT(
IIF(
MONTH(Fields!myDateColumn.Value) = MONTH(TODAY())
AND YEAR(Fields!myDateColumn.Value) = YEAR(TODAY()),
1,
Nothing
)
)
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.
I am using SSRS 2016 application to pull data from SharePoint list.
My task is to calculate the average DaysUsed and the average Percentage from a column.
It is a Matrix report which has two columns:
Sum(Fields!Days.Value)
Sum(Fields!Percentage.Value)
The task is to show the average days and average percentage.
I have tried the =Avg(Fields!Days.Value) but this shows wrong result.
UPDATE
Yes, the matrix is grouped by the Month to show each relevant month.
See the screenshot below what I have tested so far.
The DaysUsed is a calculated between 2 fields [FromDate] and [UntilDate] by summarising the total days minus the weekends. see below:
=(DateDiff(DateInterval.day,CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")), CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")))+1)
- (DateDiff(DateInterval.WeekOfYear,CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")), CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")))*2)
- IIF(Weekday( CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")),1) = 1,1,0)
- IIF(Weekday( CDate(format(Fields!FromDate.Value,"MM-dd-yyyy")),1) = 7,1,0)
- IIF(Weekday( CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")),1) = 1,1,0)
- IIF(Weekday( CDate(format(Fields!UntilDate.Value,"MM-dd-yyyy")),1) = 7,1,0)
Furthermore, the [DaysUsed] row then consists of IIF(value is null then show 0 otherwise show the total value of days used).
=IIF(IsNothing(Sum(Fields!Days.Value)), "0", Sum(Fields!Days.Value) )
Sum(Fields!Days.Value)/CountRows()
Shall give you average days. Similarly goes for others as well.
If you has a field called Fields!Days.Value, I guess your data in the screenshot is already grouped by month. This means the expression
=Avg(Fields!Days.Value)
gives you the average over all Days (sum of all days / count of all days).
If you want to use the grouped values (by mounth) you either can use the following expression when you are inside the scope (the monthly socpe; indicated by the brackets on the most left side on your tablix)
=Sum(Fields!Days.Value) / Count(Fields!Days.Value)
If you are not in the scope you have to tell the tablix that is should use your monthly grouping. For this you can use the following:
=Sum(Fields!Days.Value, "YourMonthGroupName") / Count(Fields!Days.Value, "YourMonthGroupName")
I have a matrix that creates 3 columns when it's run and I am unable to add a title to those dynamically created columns, as required by the client, and can't find any fixes or examples online. I hoped putting the matrix and textboxes into a table might work, but the same result as the images below occurs.
Is this seemingly simple thing just not possible, or is there a workaround I'm missing?
Design View
Result Textbox displayed after columns
Row and Column Groups visible
If you have 3 MTLH1 value for each NTLH2 value then you can do something like this...
(as you supplied no sample data I generated some from the sample WideWorldImporters database). My Query gives me 5 columns and results similar to the below.
CustomerCategoryName Qtr Mnth MnthName OrderValue
Computer Store 1 1 Jan 10
Computer Store 1 2 Feb 12
Computer Store 1 3 Mar 15
Computer Store 2 4 Apr 20
Corporate 1 1 Jan 11
....
Basically we end up with 3 months per quarter
I then added a matrix control to the report, dragged CustomerCategoryName to the rows, Mnth to the Columns , Qtr above Mnth so it becomes a parent column and finally OrderValue to the data "cell".
I actually swapped the Mnth field out for MnthName in the column header to make it easier to read, but the column order is still sorted by Mnth (the numeric version). I then centered the column headers for readability.
The final design looks like this
If we run the report, the result looks like this..
As you can see we have 4 groups, one for each quarter, each with 3 columns.
If you want to customise the quarter names, you could do that if required by changing the expression in the cell. For example if we wanted all quarters to have "Q" preceeding the number except the 2nd Quarter whcih we want to have a specific string then you could use something like.
=IIF(
Fields!Qtr.Value = 2,
"Second Quarter",
"Q" + Cstr(Fields!Qtr.Value)
)
The final output now looks like this...
Alternatively, you could generate all the column headers in t-sql so where I have MnthName you could create a Quartername or similar.
Hopefully this is useful. If not, please post sample data and expected results of that sample data and I'll revise the answer.
im working with report that visual studio 2010 have, then i have a chart series with four fields planta, date, and densidad, i have to get the average of all the data that densidad has but only when the date is the same for example
Date Densidad
11/05/2015 2
11/05/2015 3
12/05/2015 4
in this case i have two data from 11/05/2015 the only for that date i must get the average that in this case should be 2,5 , ive been looking for an expression that works but i ve found anything, please?
Add a new row group, then go to the group's properties and group by date. In your tablix, add in AVG(Yourdataset!Yourvalue.Value) next to the date. This should group by date.
Your group expression should look like this:
=FormatDateTime(Fields!dates.Value, DateFormat.ShortDate)