Link to home
Start Free TrialLog in
Avatar of lyptus
lyptus

asked on

SQL 2005 reporting services Previous function, scope parameter not working.

I am trying to write a report that takes a value from the previous row and subtracts it from the value in the current row. I used the previous function to get the value from the previous row. Previous(Fields!num.Value). I soon found that becuse of my grouping the first row in the next group was getting the value of the last row in the previous group. The documentation shows that previous has 2 contructors. you can pass just the value as object or the object and scope as string. So I put in =Previous(Fields!Num.Value,"tabel1_Name") It doesn't show any errors when I save it, but when I preview the report it does not compile saying he Value expression for the textbox textbox9 has an incorrect number of parameters for the function Previous. I'm guessing the documention is wrong. Does anyone now how to correctly pass the scope to the previous function? Is there an additional parameter I need to pass?
Avatar of brandonvmoore
brandonvmoore

I'm not an expert on SQL reporting services, but let me see if I can lead you in the right direction.  First, I would say that the documentation is 'probably' not wrong.  Secondly, as you saw you can't access the previous item in the table when you are grouping.

You could consider either using a subquery that isn't grouped where you can add the field you need.  Or you could just create a temporary table that adds the field you need.  

However, what you are asking for doesn't sound like it makes sense.  When you group something you are getting one row for the entire GROUP, so it wouldn't make sense to take data for the entire group and modify it by a single, previous record.  If your calculations are recursive (I'm using this term liberally as I don't have a better word at the moment.  But what I mean is that each calculation on a row is using the calculation from the last row), then you probably need an aggregate function.

Tell me the bigger picture of what you're trying to accomplish and I'll see if I can help further.
Avatar of lyptus

ASKER

Here is what the report renders.

Name(maxtime)         DateTimeOfCheck         PreviousRowDatetime.  
C4 - Brett (30)      
      04/13/2009 13:36:36  
      04/13/2009 13:42:41     04/13/2009 13:36:36                    
      04/13/2009 15:05:51     04/13/2009 13:42:41                    
     
CELL D-Brett (15)    
      04/13/2009 13:36:43     04/13/2009 15:05:51                  
      04/13/2009 13:42:29     04/13/2009 13:36:43                
      04/13/2009 15:05:43     04/13/2009 13:42:29
      04/13/2009 15:05:57     04/13/2009 15:05:43
     
CELL E-Ken  (30)  
                                            04/13/2009 15:05:57

The grouping is on the cell name. The first row of dates is the date that cell was checked. the 2nd row of dates is the date from the previous row. C4 was checked 3 times so it has 3 dates. the 2nd column then shows the previous date. The 2nd column of dates is blank in the first row because there is no previous date. Cell E at the bottom has never been checked so it does not have a date in the first column. But you can see it is grabbing the previous date from the Cell D group. I was hoping I could use the scope parameter to limit the scope to each group of names. My ultimate goal is to subtract the date time from the previous date time and verify that it is within the time frame of the MaxTime field for that location.
You're looking at documentation for 2008, but you're using 2005.  That's why it doesn't work.  Can you upgrade to 2008 or do we need to find another solution?
Avatar of lyptus

ASKER

I can probably upgrade to 2008 if I have to, but I would rather not. I currently don't have a copy so I would have to buy one. The documentation I am referring to is the pop up that comes up when I type the parenthesis after Previous. So I type Previous( and a window pops up saying what can be passed. I have attached a screen shot. If there is a solution that will work for 2005, that would be great.
previous.png
ASKER CERTIFIED SOLUTION
Avatar of brandonvmoore
brandonvmoore

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lyptus

ASKER

I am using Visual Studio 2005 Professional to build the report and SQL 2005 standard for sql server. would I have to upgrade VS or SQL or both to 2008? I am only somewhat familiar with TSQL. I will look into that as well.
You would only have to upgrade SQL Server.  If you've got an action pack subscription or can otherwise obtain a licensed copy w/o having to pay full price for it that would be ideal, but at almost a thousand dollars I'd say it's not worth it just for this.

However, SQL 2008 Express (which is free) does include the reporting capabilities and will run side by side with SQL 2005.  If you aren't using any features that are exclusive to the licensed versions of SQL Server then you could move your whole project to the free version of 2008.  Alternatively, you could attach a copy of the database (or just the tables you need for reporting) to 2008 and use replication to keep it synched up with the main database.  One cool thing about doing this is that you could have your SQL 2008 Express engine on a seperate computer so that when people run reports the report processing doesn't affect performance on the main SQL Server engine.  I'm guessing this probably isn't a big deal for you, but I thought I would point out that it is a common solution that people who use reporting features use to increase performance.
Avatar of lyptus

ASKER

Thanks for your help. After looking at TSQL I think this is the route I will take. Thanks again.