I am trying to include a cumulative total column in a matrix on a report.
This is the expression I am using at the moment:
=RunningValue(Ceiling((SUM(Fields!MINUTES.Value)/60)*4)/4,Sum,"RowGroup")
The problem is the total seems to reset on each day.
I have 3 groups on the report: Parent is Day of month, type, then sub type.
I want it so that the sub types will accumulate across the days:
So 1st june/holiday/annual = 2 - cumulative = 2
.. 2nd june/holiday/annual = 1 - cumulative = 3
rowgroup in the expression above is the 3rd level sub type group in the matrix.
Whatever I try I cannot get it to total up over the days, like i said above it seems to not carry over to the next day.
Below is a sample dataset:
+------+------------+---------+----------+---------+
| User | Date | Type | Subtype | Minutes |
+------+------------+---------+----------+---------+
| 158 | 13/02/2015 | Holiday | Annual | 90 |
| 158 | 13/02/2015 | Meeting | Training | 300 |
| 158 | 13/02/2015 | Lunch | Lunch | 60 |
| 158 | 03/06/2015 | Holiday | Annual | 120 |
| 158 | 03/06/2015 | Meeting | Meeting | 285 |
| 158 | 04/06/2015 | Holiday | Sick | 120 |
| 158 | 04/06/2015 | Holiday | Annual | 200 |
+------+------------+---------+----------+---------+
My matrix column group is the user.
The row groups are date, then type, then subtype.
I then have a total column outside the column grouping.
I'm now trying to add in to the report a cumulative total based on the type and sub-type columns, that sums up the minutes.
As an example (looking at the holiday, annual entries):
03/06/2015 - 120 minutes
13/02/2015 - 90 minutes = 210 minutes
04/06/2015 - 200 minutes = 410 minutes.
Taken from the MSDN page for RunningValue, adding a scope to your expression will have this effect.
The value for RunningValue resets to 0 for each new instance of the scope. If a group is specified, the running value is reset when the group expression changes. If a data region is specified, the running value is reset for each new instance of the data region. If a dataset is specified, the running value is not reset throughout the entire dataset.
To fix the issue, simply remove the scope:
=RunningValue(Ceiling((SUM(Fields!MINUTES.Value)/60)*4)/4,Sum)
This will have the total run across all days (As days are your top-most level). If this is incorrect could you perhaps give us an example of what the report is currently doing, and what you want it to do?
Related
Supposing the following dataset:
- product
- date
- producedUnit
How can I realize the following tale:
Product | sum of Produced Unit this day | sum of produced Unit this Month
I don't want group record so if in the dataset there are 10 product I want to display them all.
As example:
Input dataset:
+--------+-------------+---------------+
|Product | date | produced unit |
+--------+-------------+---------------+
| M&Ms | 2018-02-08 | 5 |
+--------+-------------+---------------+
| M&Ms | 2018-02-08 | 2 |
+--------+-------------+---------------+
| M&Ms | 2018-02-28 | 3 |
+--------+-------------+---------------+
| Kit Kat| 2018-02-08 | 10 |
+--------+-------------+---------------+
| Kit Kat| 2018-02-28 | 10 |
+--------+-------------+---------------+
Today is 2018-02-08
Output:
+--------+-------------------------------+---------------------------------+
|Product | sum of Produced Unit this day | sum of produced Unit this Month |
+--------+-------------------------------+---------------------------------+
| M&Ms | 7 | 10 |
+--------+-------------------------------+---------------------------------+
| M&Ms | 7 | 10 |
+--------+-------------------------------+---------------------------------+
| M&Ms | 7 | 10 |
+--------+-------------------------------+---------------------------------+
|Kit Kat | 10 | 20 |
+--------+-------------------------------+---------------------------------+
|Kit Kat | 10 | 20 |
+--------+-------------------------------+---------------------------------+
Add a calculated field to your Dataset that gets the Month of the production date. For this example, I used =Month(Fields!Date.Value), but if you are crossing years, you may need to use the first day of each month as your common value.
Add a calculated field to get the number produced today. For example:
=IIf(Fields!Date.Value = "2/8/2018", Fields!Produced.Value, Nothing)
Create a new Table. Change the "Details" group to be grouped by Month. Add a parent row group that is grouped by Product.
The expression for "sum of Produced Unit this day" would be like this:
=Sum(Fields!Produced_Today.Value)
The expression for "sum of produced Unit this Month" would be like this:
=Sum(Fields!Produced.Value)
Here's a sample of the result:
Explanation: The table first groups by Product and then by month. You could hide the month and date columns if you don't want to show those. The amount produced today is being filtered at the Dataset level. The amount produced this month is being summed within the scope of the Month group.
Obviously, this is a trivial example, but you can take the principles shown here to account for more variables such as multiple months in your dataset.
I have a complex(?) SQL query I am needing to build. We have an application that captures a simple data set for multiple clients:
ClientID | AttributeName | AttributeValue | TimeReceived
----------------------------------------------------------------
002 | att1 | 123.98 | 23:02:00 02-03-20017
----------------------------------------------------------------
003 | att2 | 987.2 | 23:02:00 02-03-20017
I need to be able to return a single record per client that looks something like this
Attribute | Hour_1 | Hour_2 | Hour_x |
--------------------------------------
att1 120.67 |
--------------------------------------
att2 | 10 | 89.3 |
The hours are to be determined by a time provided to the query. If the time was 11:00 on 02-03-20017, then hour 1 would be from 10-11 on 02-03-20017, and hour 2 from 9-10 on 02-03-20017. Attributes will be allocated to these hourly buckets based on the hour/date in their time stamp (not all buckets will have data). There will be a limit on the number of hours allocated in a single query. In summary, there are possibly 200-300 attributes and hourly blocks of up to 172 hours. To be honest I am not really sure where to start to build a query like this. Any guidance appreciated.
I have a dataset that looks like the following:
| Location | Category |Item Name | Month | QTY |
| -------- | -------- | -------- | -------- | --- |
| NY | Hardware | Screw | Jan 2017 | 100 |
| NY | Hardware | Screw | Feb 2017 | 50 |
| NY | Hardware | Screw | Mar 2017 | 75 |
| NY | Hardware | Bolt | Jan 2017 | 30 |
| NY | Hardware | Bolt | Feb 2017 | 90 |
| NY | Hardware | Bolt | Mar 2017 | 50 |
| CA | Hardware | Screw | Jan 2017 | 100 |
| CA | Hardware | Screw | Feb 2017 | 50 |
| CA | Hardware | Screw | Mar 2017 | 75 |
| CA | Hardware | Bolt | Jan 2017 | 30 |
| CA | Hardware | Bolt | Feb 2017 | 90 |
| CA | Hardware | Bolt | Mar 2017 | 50 |
My report needs to look like the following:
| Hardware | Screw | Bolt |
|Current Month Total | 150 | 100 |
|Yearly Total | 450 | 340 |
I need a way to limit the current month total to ONLY the current month but aggregate the values for the yearly total. I've tried using LAST in the aggregate but you can't. I've tried the following for the current month total aggregate. My Date value is the 1st day of the month and my parameter is the last day of the month, so I needed a way to match the 2 that is why there is the date addition. The jist is to try and match the current month, which is a parameter to the date column:
=iif( DateAdd(dateinterval.Day,-1,DateAdd(dateinterval.Month,1,Fields!Sale_DATE.Value)) = Parameters!ReportingDate.Value, iif(isnothing(sum(Fields!Total.Value)),"",sum(Fields!Total.Value)),sum(0))
but it only works if the query that returns the dataset returns ONLY the current month. If the query returns all of the months in the year it shows 0's. I need a way to filter the cells so they aggregate the values correctly
If I limit my report to only the current month I can't get the yearly aggregate and if I select all of the months I can't get the current month total.
You can do this using the built-in grouping functions without any fancy expressions.
Add a row group by month. Filter the row group to the current month. Add a column group by Item Name. Add a row outside and below the row group to get your yearly totals. The expressions will all simply be a sum of the Qty. The report will take care of summing the values within each group scope.
Actually, using grouping as suggested alone doesn't work. I was already using groups in my matrix. The issue is that I needed a different form of grouping within the same column and I needed to restrict the grouping to different date ranges. My problem was that I had the SUM in the wrong position in my formula.
The expressions for the yearly total should have been:
=Sum(IIF(Fields!ItemName.Value="Screw",Fields!QTY.Value,0))
=Sum(IIF(Fields!ItemName.Value="Bolt",Fields!QTY.Value,0))
Then, based on the dataset, if the current month is "Mar 2017" I can build the expression for Month Total as
=Sum(IIF(Fields!ItemName.Value="Screw" and Fields!Month.Value="Mar 2017",Fields!QTY.Value,0))``
=Sum(IIF(Fields!ItemName.Value="Bolt" and Fields!Month.Value="Mar 2017",Fields!QTY.Value,0))
These examples are using my sample dataset in this question. Since I couldn't hard code dates, wanted to use parameters, and needed to do a calculation this is what I ACTUALLY used:
SUM(iif(DateAdd(dateinterval.Day,-1,DateAdd(dateinterval.Month,1,Fields!REL_DATE.Value))= Parameters!ReportingDate.Value,
Fields!Total_OnTime.Value,0))/SUM(iif(DateAdd(dateinterval.Day,-1,DateAdd(dateinterval.Month,1,Fields!REL_DATE.Value))= Parameters!ReportingDate.Value,
Fields!Total.Value,0))
Hope this helps someone else.
I have a weekly sales report across several locations. I need to include the week's total and the running total for each.
Location | Week1 | Week2 | Week 3 | Total
____________________________________________________________
Boston | $45000 | $48000 | $54000 | $147000
------------------------------------------------------------
Boston RTotal | $45000 | $93000 | $147000 |
------------------------------------------------------------
New York | $78000 | $84000 | $92000 |
------------------------------------------------------------
New York RTotal | $78000 | $162000 | $254000 | $254000
I think you can achieve that by using RUNNINGVALUE function and playing around with matrix grouping settings.
First create a matrix with these groups:
Now in the highlighted cell use the following expression:
=RunningValue(Sum(Fields!Sales.Value),Sum,"Location")
Note Location is a group in my matrix.
RunningValue will evaluate the Sum(Fields!Sales.Value) expression and sum the values in the given scope. When you preview the report it will produce the following matrix:
Hopefully this is what you require, let me know if it helps.
I have a view set up like the below table, which is pulling data from multiple other tables using JOINS. Basically I'm trying to replicate a Crystal Report that breaks up the data below into Job # - Weekly (hrs) - TotalToDate(hrs) - Budget(hrs)
And this is broken up per department. The way the report does it is it'll display the hours for the last week, then the total hours to date then the budgeted hours set for that department.
Table doesn't reflect above - just an example of what DB table looks like.
+-----------+------------+---------------+--------+---------------------+
| Job | Work_Date | Work_Center | Est_Total_Hrs | Act_Run_Hrs |
+-----------+------------+---------------+--------+------+--------------+
| 5666 | 2014-02-23 | SURFACE | 155 | 5 |
| 5666 | 2014-02-16 | SURFACE | 155 | 3 |
| 5666 | 2014-02-23 | DESIGN | 200 | 6 |
| 5666 | 2014-02-16 | DESIGN | 200 | 4 |
| 5666 | 2014-02-23 | SURFACE | 150 | 2 |
| 5666 | 2014-02-16 | SURFACE | 150 | 2 |
| 5666 | 2014-02-23 | DESIGN | 300 | 8 |
+-----------+------------+---------------+---------------+--------------+
Also, theres a lot of different job numbers, and when I pull up more than 1 job in Crystal it'll show the report like the picture above but with all jobs I want to retrieve.
How would I go about pulling this data so it shows up the same way in the Crystal Report? I want to create a view that looks the same. Is there a way to see how Crystal does it? When I click "Show Query" it shows me the below query which I had to re-write a little bit for it to work in SQL Server and in Adminer.
Query I'm using to pull ALL data for all Jobs within an updated Work_Date in the last 90 days.
SELECT Job_Operation.Work_Center
,Job_Operation.Job_Operation
,Job_Operation_Time.Work_Date
,Job_Operation.Est_Total_Hrs
,Job_Operation_Time.Act_Run_Hrs
,Job_Operation_Time.Act_Setup_Hrs
,Job.Description
,Job_Operation_Time.Overtime_Hrs
,Job_Operation_Time.Act_Setup_Hrs
,Job.Job
,Job.Description
,Job_Operation_Time.Labor_Burden
,Job_Operation.Est_Setup_Labor
,Job_Operation.Est_Run_Labor
,Job_Operation.Est_Labor_Burden
,Job_Operation.Operation_Service
FROM Job AS Job
LEFT OUTER JOIN Job_Operation AS Job_Operation ON Job.Job = Job_Operation.Job
LEFT OUTER JOIN Job_Operation_Time AS Job_Operation_Time ON Job_Operation.Job_Operation = Job_Operation_Time.Job_Operation
WHERE DATEDIFF(day, Work_Date, GETDATE()) < 90 ORDER BY Work_Date Desc
Crystal will take the data from a query and does its internal manipulation as per the design of the report, So if you need the table exactly as you view the report then along with the query in crystal report you need to make some changes.
Suggestions:
Your report has only 6 columns but you query has more than 10 columns so you need to change the query so that it has only 6 columns.
Report has data according to the week but query has hourly data so you need to write some functions in query so that you manage to get weekly data from hour data
You said when you take more than 1 ID you get in the given format then in that case add some group by conditions to the resultant query so that all data is grouped. for e.g if you need only one ID then group by ID so that there is only one record for a ID.
Try adding some group by conditions some date formulas to get exact output