0
votes

I have a table built off a dataset containing timesheet data with possible multiple entries per day (day_date) for a given person. The table is grouped on day_date. The field for hours is effort_hr (see dataset and report layout below).

The table generates a single row with one column for each day (as expected).

For each day I want only one value (total hours for person) so the expression is Sum(Fields!effort_hr.Value) This is properly adding up all the hours for each day.

Now I add a total column at the end of the row to see ALL the hours for the whole timesheet. The expression in the total column cell is Sum(Fields!effort_hr.Value) which is exactly the same as the daily ones. Again, this is adding up all hours for the timesheet.

So this is working great.


I now need a new row that only shows a max of 8 hours per day. So if the person works less, it shows less, but if the person works more, show a max of 8.

In this case, the daily column expression is:

 IIF(Sum(Fields!effort_hr.Value)>8.0,8.0,Sum(Fields!effort_hr.Value)) 

And again, it displays perfectly for each day.

The total for this row is where I run into trouble. I have tried so many ways, but I cannot get the total for the columns in this row. The report keeps showing an #Error in the cell. The report saves fine and there is no error in the expr.

The problem seems to come from the fact that there are 2 values for a given day. So in other words, for 5 days, the person has 6 entries. When I try it for a person with only 5 entries, no problem.

I have tried:

Sum(IIF(Sum(Fields!effort_hr.Value)>8.0,8.0,Sum(Fields!effort_hr.Value)))

RunningValue(IIF(Sum(Fields!effort_hr.Value)>8.0,8.0,Sum(Fields!effort_hr.Value)),Sum,Nothing)

I either get an #Error, or I get the wrong total. Is there any way to just get a total for the cell values in the table? The daily numbers are correct, just give me the total at the end (like Excel).

I could do this in the SQL, but that would mess up other parts of this report.

DataSet:

res_name   |   day_date   |   effort_hr

J. Doe   |   Apr 6, 2015   |   2

J. Doe   |   Apr 6, 2015   |   9

J. Doe   |   Apr 7, 2015   |   8

J. Doe   |   Apr 8, 2015   |   7

J. Doe   |   Apr 9, 2015   |   10

J. Doe   |   Apr 10, 2015   |   9

REPORT TABLE Layout:

           |   Apr 6   |   Apr 7   |   Apr 8   |   Apr 9   |   Apr 10   |   Totals

Total   |      11       |       8      |       7      |      10    |       9       |      45

Reg    |      8       |       8      |       7      |      8    |       8       |      39

OT     |      3       |       0      |       0      |      2    |       1       |      6

Problem:

Row 1 Column Total works great and gives 45 hours ;

Row 2 Column Total either gives #Error, 41, or some other wrong number - just need it to total the actual values of each cell in the row ;

same problem for Row 3 total

Thanks in advance for your time!

2
Can you show the sample data in the way it in your dataset (table). And also the tabular format for expected result. It will be easy to understand this way.wonderbell
I tried my best to display the dataset and the report layout I am looking for with this markup in my original post (hope the columns line up). Thanks.Karcs

2 Answers

1
votes

I used your input data and tried to create the report in given format. I used following function for Row 2 Total

=Sum(IIF(Fields!Efforts.Value>8.0,8.0,Fields!Efforts.Value),"DataSet1",Recursive)

This shows sum as 39 for second row. You can try and let me know if it works for you. If it doesn't I will list the exact steps how I created Matrix and groups.

Note: Don't forget to put your dataset name in the second argument of function Sum. And Recursive, as clear by name, applies Sum recursively for the group.

Update: I followed following steps. 1. Add a Matrix on the report. 2. Under Column group section on Matrix, Select any column name from the dataset. (Otherwise it won't show any columns in the next step) 2. Right click Column --> Add Group --> (Under column group) Add Parent Group. Select Day as Group By --> OK. It will create a new row. Put expression Sum(Efforts) in first row. And your expression =IIF(Sum(Fields!Efforts.Value)>8.0,8.0,Sum(Fields!Efforts.Value)) in the second row. enter image description here

  1. Right click on the column group section in the group pane --> Select Add Total --> After. It will add new column at the end of Matrix. Put expression Sum(Efforts) in first row and expression =Sum(IIF(Fields!Efforts.Value>8.0,8.0,Fields!Efforts.Value),"DataSet1",Recursive) in the second row. enter image description here

  2. Save and run you should see following in the report. enter image description here

Remember to change the names of columns and dataset as par your code. This is an idea on how to do such grouping, obviously you'd need to do changes for the headers and the 3rd row etc.

HTH.

1
votes

Posting another answer as the previous one has become so long.

I referred to this MSDN link, and used the selected answer. Apparently we need to use custom code to achieve this (if you are not willing to change your dataset and have the calculated values in there).

  1. Right click on report --> report properties --> Go to tab 'Code' --> Paste this

    Dim public nettotal as Double Public Function Getvalue (ByVal subtotal AS Double) AS Double nettotal = nettotal+ subtotal return subtotal End Function Public Function Totalvalue() return nettotal End Function

  2. In the row group expression of second row put

    = code.Getvalue(IIF(Sum(Fields!Efforts.Value)>8.0,8.0,Sum(Fields!Efforts.Value)))

  3. In the Total cell expression (for second row) put

    =code.Totalvalue()

  4. Save and run, you should see following result.

The Result