Calculate time difference between 2 columns in SSRS - reporting-services

I've got two fields that are calculated as per the below:
=Format(DateAdd("s", Sum(Fields!TalkTime.Value) / Sum(Fields!EmployeesWorked.Value), "00:00:00"), "HH:mm:ss")
and
=PREVIOUS(Format(DateAdd("s", Sum(Fields!TalkTime.Value) / Sum(Fields!EmployeesWorked.Value), "00:00:00"), "HH:mm:ss"),
"Quarter1")
I've got a separate column to calculate the difference between the 2 columns:
=ReportItems!Textbox2625.Value - ReportItems!Textbox29.Value
However, when I run the report, the column that I used to calculate the difference between the 2 fields shows '#Error'. I'm assuming there's some kind of formatting problem, but I'm not sure how to fix it?

Format returns a string, so you aren't trying to subtract two dates, you are trying to subtract two strings, which is throwing an error.
Firstly, use a date calculation for the Value expression:
=DateAdd("s", Sum(Fields!TalkTime.Value) / Sum(Fields!EmployeesWorked.Value), "00:00:00")
This calulates the Sum of the TalkTime over the Sum of the EmployeesWorked time for the scope of the textbox.
Put the formating into the Format property: HH:mm:ss
This separates the value of the textbox (the time) from its presentation. Now you might be able to do your calculation:
=ReportItems!Textbox2625.Value - ReportItems!Textbox29.Value
Again, put the formating into the Format property: HH:mm:ss so it displays as a time.
If this doesn't work, put the calculation in full (excluding the Format functions, but see note below on why you might not be using the Previous function correctly):
=DateAdd("s", Sum(Fields!TalkTime.Value) / Sum(Fields!EmployeesWorked.Value), "00:00:00")
- PREVIOUS(DateAdd("s", Sum(Fields!TalkTime.Value) / Sum(Fields!EmployeesWorked.Value), "00:00:00"), "Quarter1")
Note that aggregating within the Previous function and specifying the scope (in this instance "Quarter1") requires the specified scope ("Quarter1") to be a containing scope for the current scope of that ReportItem.
For example, you might have a table with three nested levels of grouping: by Year, then by Month, then by Day. The expression =Previous(Sum(Fields!Sales.Value, "Day"), "Year") in a row associated with the group Day will return the sales value for the same day and month for the scope of previous year.
If expression contains an aggregate function that specifies a scope other than the default, the scope parameter for the Previous function must be a containing scope for the scope specified in the aggregate function call - in other words, the textboxes must be in a child scope of the "Quarter1" scope. While I don't know the scoping you are using, from your wording it looks like you are trying to get the calculation from a dataset which has the value from the first quarter, not a containing group scope? If so, you don't need the Previous function, you can just calculate the aggregate over the entire dataset "Quarter1" in the Sum function like so:
=DateAdd("s", Sum(Fields!TalkTime.Value, "Quarter1") / Sum(Fields!EmployeesWorked.Value, "Quarter1"), "00:00:00"))

Related

Expression to calculate % in a report

I am building a report(report server project) using the Data Tools. I have a column Quantity it has a Total.
I need another column that calculate the share(%) of each line in the Quantity comparing to the Total.
The expression would be: Line_1_Share = Quantity_of_line_1/Total.
I tried =[Sum(Total/Quantity)] but it does not even accept as a valid expression.
If you right-click the textboxes that contain your working 'Quantity' and 'Total' values and look at the expressions you will see the correct format.
For exmaple your 'Quantity' expression might be something like
=Fields!Quantity.Value
or if it is in a grouped row it might be
=SUM(Fields!Quantity.Value)
your 'Total' expression might also be
=SUM(Fields!Quantity.Value)
When you use SUM() (or any similar aggregate) then the scope of the expression decides what is included in the sum. The scope can be a single row, a row group or an entire dataset. If you do not specify a scope then the position of the textbox determines the scope.
So, if you have a simple table with no grouping other than the total line and your dataset name is dataset1 then your expression would need to be
=Fields!Quantity.Value / SUM(Fields!Quantity.Value, "dataset1")
The above reads .... "For the current row, take the Quantity and divide is but the sum of all Quantities that are within the entire dataset called dataset1"
If this does not help, post your current report design including and row and/or column groups.

Can you set a parameter that references an expression field that is calculated based on another parameter selection?

I am attempting to create a parameter which looks at the values of a field in the report which is calculated based on the entry of another parameter.
Specifically, the first parameter is a number option (30,60 or 90) and the field expression is a DATEADD that adds the parameter value to the value of a date field.
The next parameter I need is to pick dates in the "expression field" that fall into a certain range. i.e. user chooses 30 so the report generates and populates the "Hire Date" + 30.
I want to then only select the records where that new date falls into a specified range i.e. Effective Date 2/1/2020-2/29/2020. I have been looking everywhere, but cannot find an answer and I don't know if it is possible.
Results example
[EffDate Field[\]\[1\]][1]
I think this was what SuperSimmer 44 was referring to that I couldn't understand before.
I added the following parameters:
Wait - which is an integer & has set available values of 30, 60 & 90
From - Date
To - Date
I kept the field "Effective Date" in my report which was the expression =DateAdd("d",Parameters!wait.Value,Fields!HireDate.Value)
I then added a filter to the Dataset that said if the value of the expression =DateAdd("d",Parameters!wait.Value,Fields!HireDate.Value) was between #from & #to then they should include the record in the results. It worked perfectly.
Report Sample
Insert 2 parameters, one called qty to hold available values from a list 30/60/90 or 120 etc
the other called date to hold your from effective date.
Set up a calculated field in your dataset called effectivedate that utilised DateAdd, for example ie: =DateAdd("d",Parameters!qty.Value,Parameters!effectivedate.Value)
Then set a filter on your dataset that utilizes this calculated field.

SSRS select parameter month and change par. first and last day of this month

i need to create parameter list of months and then (after select) recalculate two others paramateres in date format ([first day] and [last day]) of this month, can you please help me?
You are querying a database server to generate the list of months, although there's no need to do that. I suggest to rather create a list of months in the report and let the report calculate the month's names, so the language depends on the Language setting of the report (which can be the language configured in the user's browser).
For example, to calculate the Label for the Value 1, use an expression like =MonthName(1).
The Parameters FirstDay and LastDay (or just the values whenever you need them) can be calculated using these expressions:
FirstDay: =DateSerial(Today.Year, Parameters!Month.Value, 1)
LastDay: =DateSerial(Today.Year, Parameters!Month.Value, 1).AddMonths(1).AddDays(-1)

query of calculate the annual profit growth in qlikview by using text object

I want to calculate the annual average profit growth rate for 5 years by using a text object. Qlikview does not seem to support nested aggregation... I am new to QlikView, can anyone can help me?
Tried query:
='Annual Growth Rate (2003-2007) :' & avg((sum(Profit_per_Product)/sum(Total_Retail_Price))*100)
Thanks in advance!
QlikView does support nested aggregation and can fulfil your requirements if you utilise the AGGR function. This function allows you to perform aggregation over a set of dimensions that you specify and in its simplest form, can be use as follows:
=aggr(expression,dimension)
This means that expression is evaluated for each value of dimension. For example, in your case if you used sum(Profit_per_Product)/sum(Total_Retail_Price) as your expression, and used your dimension that contained your data's year, then aggr would result in five different values (one for each change in your year). As you wish to take the average, then the AVG function happily takes these five values and provides you with your desired result.
Therefore, all you need to do is to slightly change your expression to the following (here I assumed that your dimension that contains the year is named Year):
='Annual Growth Rate (2003-2007):' & num(avg(aggr(sum(Profit_per_Product)/sum(Total_Retail_Price),Year)),'0.00%')
I also added the NUM function to format your result as a percentage.
More information on Advanced Aggregation (i.e. AGGR) may be found in section 25.2 of the QlikView Reference Manual (in my copy it's on page 291).

Use a summary field in an expression in SSRS reports

I have the details of my report being summed up in a summary expression, all works fine. The fields are decimal values of hours worked. Thus, the summary value is also a decimal value. I'd like to access the summary value and convert it to hours / minutes. I've labeled the express as "WorkTimeSum", but can't seem to get a handle to it, however. Fields! obviously won't work since it is a summary expression. I was thinking ReportItems! should work, but to no avail. How can I use this expression field (in a summary row) in an expression in the same summary row?
If I've understood correctly, you're asking how to reference the textbox containing the total work hours value so that you can convert it to hours and minutes using an expression in a different textbox?
You can use either ReportItems! e.g.
=ReportItems!Textbox20.Value)
or ReportItems("") e.g.
=ReportItems("Textbox20").Value
to reference the value of another textbox. Be careful with the names as they are case sensitive.
You can use aggregate functions in any expression. For example, in any header rows you can use the following expression to determine the total hours value:
=Floor(Sum(Fields!hours.Value))
Sum(Fields!hours.Value) is just the total hours in whatever context, e.g. the group total if it's a group header row; you can use this expression as an input in any other expression you require.
It sounds like your issue wasn't the conversion itself, so hopefully this points you in the right direction. If you need further information please specify.