Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Wednesday, March 28, 2012

RunningValue ?

I am having problems with the following -

this represents the dataset Date Customer Voucher Number Document Amount Check Amount 7/15/2006 Company G 101 15.00 45.00 7/15/2006 Compnay G 101 25.00 45.00 7/15/2006 Compnay G 101 5.00 45.00 7/18/2006 Company A 102 35.00 35.00 7/25/2006 Company M 103 45.00 50.00 7/25/2006 Company M 103 15.00 50.00

This represents the final report this is what I am getting Date Customer Voucher Number Document Amount Check Amount Check Amount (Hidden) Group 1 Header = Voucher Number (Hidden) Detail 7/15/2006 Company G 101 15.00 45.00 45.00 (Hidden) Detail 7/15/2006 Company G 101 25.00 45.00 45.00 (Hidden) Detail 7/15/2006 Company G 101 5.00 45.00 45.00 Group 1Footer 7/16/2006 Company G 45.00 45.00 135.00 (Hidden) Group1Header = Voucher Number (Hidden) Detail 7/18/2006 Company A 102 35.00 35.00 35.00 Group 1 Footer 7/19/2006 Company A 35.00 35.00 35.00 (Hidden) Group 1 Header = Voucher Number (Hidden) Detail 7/25/2006 Company M 103 45.00 50.00 50.00 (Hidden) Detail 7/25/2006 Company M 103 15.00 50.00 50.00 Group 1 Footer 7/25/2006 Company M 103 60.00 50.00 100.00 Report Footer Grand Total: 140.00 130.00 270.00

(I am using a table)

I can get the correct total for the Group 1 Footer Check Amount by dividing the Total by a count of the Voucher Numbers, but I have not been able to add the Group 1 totals of the Check Amount for the Grand Total in the footer. I have made various attempts using RunningValue with the Group 1 Check Amount Total field, but always getting a error - mostly that the scope was not correct.

Any suggestions will be appreciated.

Ok, so I solved my own problem. Maybe this will help you. I summed the Group 1 Footer cells with the correct Check Amount totals (45, 35,50) in a textbox in the Report Footer =Sum(ReportItems!CHEKTOTL_1.value). Voila! I was trying to make this way too complicated!|||

I am having the exact same problem and have tried about four different approaches without success.

Where are my CRW running totals?!

I my case it is cash receipts and applications (whereas your case appears to be payables).

How did you get your group 1 footer to get just the check amount. I have tried summing a iif(...) where only the first row of a check shows the value - and this did not work (cannot sum a calculation!). You indicate that you divided the total by the number of rows - would you mind showing the expression.

How then did you get this expression in the group 1 footer to be summed - I have all but givin up on runningvalue due to scope issues - this also killed my attempt at VBA code.

Thanks

Philip Neufeld

|||

Here is my solution. I hope my explanation makes sense.

I did some aggregating in the the SQL statement - summing the DocAmount and grouping by Voucher Number, Voucher Date, Check Total and Vendor.

My report is for multiple companies, so in the design portion I used a list data region sorted by company. Then I added a table, grouped by Company.

I put the Date, Voucher Number, Vendor, Voucher Amount and Check Amount in the detail rows of the table and summed the Voucher Amount and Check Total in the Table Summary row.

On the General tab of the table properties, I checked Insert a page break after this table and Fit table on one page if possible. When the report is exported to Excel, each company appears on a separate worksheet and the summaries also appear. That was another problem I was having with another solution I had devised - the totals appeared on my screen in the Reporting Manager, but apparently the formulas that I used to get the totals weren't exporting into Excel.

Hope this helps!

sjm

sql

RunningTotal (for the birds)

How do I solve this RDL chart problem?

A bird watcher records the date each time he spots a new type of bird ('NewBird'). Likewise, he records the date of each time he spots a previously known type of bird ('OldBird'). Like this:

SpotDate Event
01/01/07 NewBird
01/01/07 NewBird
01/01/07 NewBird
01/02/07 OldBird
01/02/07 NewBird
01/02/07 OldBird
01/06/07 NewBird
01/06/07 OldBird
01/06/07 OldBird

I want to make an RDL chart that shows a running total of 'NewBird' to 'OldBird' along the date timeline. I am using SQL suite 2K5. I figure my "Category" field should be 'SpotDate', my series field should be 'Event,' and my "Data" field should be some kind of "=RunningTotal(Event, ?)". Is this correct?

And for that matter, how do I convince the RDL chart to include the elapsed time (the missing days between Jan 1, and Jan 6 in the plot)?

Ok, it seems the answer (mostly) to my own question is this:

1) Create a select statement that provides the daily total (e.g. called "Tally") grouped by SpotDate and Event.

2) In the chart, add the SpotDate to the category, the Event to the series, and the "Tally" as the value

3) Edit the "Tally" properties so that its 'value' field shows '=RunningValue(Fields!Tally.Value, Sum, "chart1_SeriesGroup1")

Thats it! The name "chart1_SeriesGroup1" was chosen simply to match the auto-generated name Visual Studio gave to the "Event" series (you can find or edit this name by selecting the 'data' tab on chart properties. One final piece of advice: do not "add" a new dataset field that contains a "RunningValue" calculated value...it causes Visual Studio to crash every time you view a chart (whether or not you used it on the chart).

So now my only remaining issue, is the need to convince the RDL chart to include the elapsed time (the missing days between Jan 1, and Jan 6 in the plot) that I showed as example data earlier.

|||

> need to convince the RDL chart to include the elapsed time (the missing days between Jan 1, and Jan 6 in the plot)

Set the x-axis to use scalar mode and make sure the category grouping expression returns DateTime objects (not data values as strings).

For more information, you may want to read the following section of a technical article on SSRS charts: http://msdn2.microsoft.com/en-us/library/aa964128.aspx#moressrscharts_topic3

-- Robert

Monday, March 26, 2012

Running Totals

We are trying to create a report that shows a Week to Date, Month to Date, and Year to Date

Week to Date Month to Date Year to Date

Item Number

I've tried using an if statement (if date = current week, Qty, 0) and then sum the data but I get an error message that reportitems can only be summed in the page header and footer. I've also tried running totals, but it doesn't like the iif statement. Any ideas on how to do this?

Nancy

Nancy,

Here's an example of running values with a IIF statement. I believe you can accomplish what you're trying to do the same way.

RunningValue(IIf(Fields!elca_employer_number.Value<0,Fields!elca_employer_number.Value,nothing),count,nothing)

Ham

|||

I have the Week to Date and Year to Date working but the period (or month to date) is still causing problems.

The data comes in at the weekly level, so I was able to use:

=iif(Fields!WEEK.Value=Sum(Fields!CurrentWeek.Value, "Current"),Sum(Fields!Ordered.Value),0)

The Year to Date is was able to do a simply sum, but for the Period to Date totals I'm still stuck.

When I try:

=RunningValue(iif(Fields!Period.Value=Sum(Fields!CurrentPeriod.Value, "Current"),Sum(Fields!Ordered.Value),0),sum, Group3)

I get an error - The value expression for the textbox contains an agrregate funtion in the argument to another aggregate function.

I'm trying to evaulate if the Period in my main dataset is equal to the Period in the Current dataset. That part is easy. Then I need to sum that up and display the data on one line

WTD PTD YTD

Item 5 50 500

In Crystal Reports I would have created a field called Period_Ordered that evaluates the if Period=Current Period, then I would have summed the Period_Ordered field in my group footer. Visual Studio doesn't seem to allow this. Very frustrating.

|||

NCL,

Okay we have a partial answer,

On the this statement: RunningValue(iif(Fields!Period.Value=Sum(Fields!CurrentPeriod.Value, "Current"),Sum(Fields!Ordered.Value),0),sum, Group3) you have to remove the "SUM" values because you cannot aggregate inside of an aggregate function.

I do not think you need runningvalues because you are looking at your final totals. I believe this is all you need now. IIF(SUM(Fields!Period.Value,"Current")=Sum(Fields!CurrentPeriod.Value, "Current"),Sum(Fields!Ordered.Value),0)

Ham

|||

On the first one: the sum(fields!CurrentPeriod.Value,"Current") is coming from the dataset. The dataset only contains one line of data. It takes the current date and pulls back the valid Fiscal Week, Period and Year. Not sure why only the sum is available to add to my expression. Maybe that is a different issue.

I tried the second option but it's not calculating the data correctly. It's not summing all of the weeks in current period.

If Current dataset is pulling back today - 1/23/2007 Current Week =30 Current Period = 7

Report pulls:

Item Week Period Year Qty Current Week Current Peroid to date Year to Date

Details:

99999 1 1 2007 5 0 0 5

99999 6 2 2007 10 0 0 15

99999 29 7 2007 10 0 10 25

99999 30 7 2007 5 5 15 30

What I need the report to show in the item group footer is:

99999 5 15 30

Any ideas?

|||

N,

On your question for

What I need the report to show in the item group footer is:

99999 5 15 30

I going to go on the assume that you are return a field name period and a second field name currentPeriod

Fields!Item.value

Fields!CurrentWeek.value

Sum(IIF(Fields!Period.value = Fields!CurrentPeriod.value, Fields!Qty.value,0))

Sum(Fields!Qty.value)

I hope this helps.

Ham

sql

Running Total Query

Hi Everyone,
I have a query that returns list of accounts with their tranasaction
amount, date, and a running total for the balance. It looks like this:
SELECT acount,transDate,Amount,(SELECT SUM(AMOUNT) FROM transactions B
where B.transDate<=A.transDate and B.Account=A.Account) as Balance from
transactions A
It produces something like the following:
Account trnasDate Amount Balance
-- -- -- --
aaaaaa 01/01/2005 10 10
aaaaaa 01/01/2005 20 30 <--
bbbbbb 01/01/2005 50 50
bbbbbb 01/01/2005 -30 20 <--
I need to get the ending balance of each account for each day. So for
account 'aaaaaa' I need to get 30 and 20 for account 'bbbbbb'. In
Microsoft Access I used to use LAST(Column) method. But I do not know
now how to do it in SQL Server. For example in Access I would run the
following queery against the above query and it will do it:
SELECT transDate, LAST(Balance) from aboveQuery group by
account,transDate order by account,transDate;
Thanks
*** Sent via Developersdex http://www.examnotes.net ***Select Account, TransDate
, Sum(Amount) As DailyTotal
, Sum(Balance) As DailyBalance
From Transactions As T
Group By T.Account, T.TransDate
If you wanted the balances for a specific range of dates, simply add a Where
clause like so:
Select Account, TransDate
, Sum(Amount) As DailyTotal
, Sum(Balance) As DailyBalance
From Transactions As T
Where T.TransDate >= '20050101' And T.TransDate <= '20050131'
Group By T.Account, T.TransDate
HTH
Thomas|||--BEGIN PGP SIGNED MESSAGE--
Hash: SHA1
Something like this:
SELECT C.Account, C.transDate, C.Balance
FROM (
SELECT A.Account, A.transDate, A.Amount,
(SELECT SUM(B.Amount)
FROM transactions B
WHERE B.transDate <= A.transDate
AND B.Account=A.Account) As Balance
FROM transactions A ) As C
WHERE C.transDate = (SELECT MAX(D.transDate)
FROM transactions D
WHERE D.Account=C.Account)
ORDER BY C.Account, C.transDate
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
--BEGIN PGP SIGNATURE--
Version: PGP for Personal Privacy 5.0
Charset: noconv
iQA/ AwUBQmmkc4echKqOuFEgEQLuOgCgubKOpyICO2eW
tqXffbr7NZxG9cIAoPCu
pmxZbB9udscUSv55WJgi+qbN
=qdg0
--END PGP SIGNATURE--
Hussain Al-Dhaheri wrote:
> Hi Everyone,
> I have a query that returns list of accounts with their tranasaction
> amount, date, and a running total for the balance. It looks like this:
> SELECT acount,transDate,Amount,(SELECT SUM(AMOUNT) FROM transactions B
> where B.transDate<=A.transDate and B.Account=A.Account) as Balance from
> transactions A
> It produces something like the following:
> Account trnasDate Amount Balance
> -- -- -- --
> aaaaaa 01/01/2005 10 10
> aaaaaa 01/01/2005 20 30 <--
> bbbbbb 01/01/2005 50 50
> bbbbbb 01/01/2005 -30 20 <--
> I need to get the ending balance of each account for each day. So for
> account 'aaaaaa' I need to get 30 and 20 for account 'bbbbbb'. In
> Microsoft Access I used to use LAST(Column) method. But I do not know
> now how to do it in SQL Server. For example in Access I would run the
> following queery against the above query and it will do it:
> SELECT transDate, LAST(Balance) from aboveQuery group by
> account,transDate order by account,transDate;|||Thank you for the reply. The first query is a view which is used by so
many other queries in the system. And really there is no problem with it
and doing what it is supposed to do. My problem is with the second query
in which I can not choose the last record of records with the same date.
I tried MAX(transDate), but since the date are the same ('2005/01/01')
is returns the first occurance.
*** Sent via Developersdex http://www.examnotes.net ***|||Thank you for the reply. The first query is a view which is used by so
many other queries in the system. And really there is no problem with it
and doing what it is supposed to do. My problem is with the second query
in which I can not choose the last record of records with the same date.
I tried MAX(transDate), but since the date are the same ('2005/01/01')
is returns the first occurance.
*** Sent via Developersdex http://www.examnotes.net ***|||On Fri, 22 Apr 2005 21:18:36 -0700, Hussain Al-Dhaheri wrote:

>Thank you for the reply. The first query is a view which is used by so
>many other queries in the system. And really there is no problem with it
>and doing what it is supposed to do. My problem is with the second query
>in which I can not choose the last record of records with the same date.
>I tried MAX(transDate), but since the date are the same ('2005/01/01')
>is returns the first occurance.
Hi Hussain,
IN a relational database, there is no such thing as a "first" or "last"
row. A table is, by definition, an UNordered collection or rows. The
terms "first" and "last" can only have meaning in the context of an
ordering imposed on the rows - and that ordering can onlyt be based on
data that is stored in the table.
If the transDate column includes time as well as date, then you can use
the query posted by MGFoster.
If you have other data in your tables that can determine which of the
rows with the same transDate is the "last", then you can probably use a
variation on MGFoster's code - but I can't tell for sure without first
knowing WHAT data in your tables can be used to determine which row is
"last", and HOW to determine it.
If there is no way to determine "last" row using only the data in your
table, than there is no way to return the information you need. You'll
have to change the table design, to include the information needed to
identify the "last" row. And then, you'll have to manually repair the
rows already in the database that lack this information.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||I agree with you that RD does not provide any mechanizem for moving
sequentially through records without any specific information(key). The
first query I mentioned is a VIEW that I can not change. I want to write
another query which gets the last 'balance' of each account for each
day. None of the supplied queries do the job. The transaction date
includes time to the millisecond. My problem is when I want to group by
transaction date I have to include 'balance' as an aggregate field which
I can not. FIRST in Access allows me to get the value of 'balance'
without beging aggregated. So, is there a way to get 'balance' with
SUM/AVG/MAX/so on?
*** Sent via Developersdex http://www.examnotes.net ***|||On Sun, 24 Apr 2005 00:41:30 -0700, Hussain Al-Dhaheri wrote:

>I agree with you that RD does not provide any mechanizem for moving
>sequentially through records without any specific information(key). The
>first query I mentioned is a VIEW that I can not change. I want to write
>another query which gets the last 'balance' of each account for each
>day. None of the supplied queries do the job. The transaction date
>includes time to the millisecond. My problem is when I want to group by
>transaction date I have to include 'balance' as an aggregate field which
>I can not. FIRST in Access allows me to get the value of 'balance'
>without beging aggregated. So, is there a way to get 'balance' with
>SUM/AVG/MAX/so on?
Hi Hussain,
If the time portion is included in the view as well, then your problem
is equivalent to the problem of extracting the total amount and closing
balance from the following table:
CREATE TABLE Trans
(Account char(6) NOT NULL,
TransDate datetime NOT NULL,
Amount decimal (10,2) NOT NULL,
Balance decimal (10,2) NOT NULL,
PRIMARY KEY (Account, TransDate)
)
go
INSERT INTO Trans (Account, TransDate, Amount, Balance)
SELECT 'aaaaaa', '2005-01-01T10:00:00.000', 10, 10 UNION ALL
SELECT 'aaaaaa', '2005-01-01T20:00:00.000', 20, 30 UNION ALL
SELECT 'bbbbbb', '2005-01-01T13:00:00.000', 50, 50 UNION ALL
SELECT 'bbbbbb', '2005-01-01T14:00:00.000',-30, 20 UNION ALL
SELECT 'bbbbbb', '2005-01-02T12:00:00.000',-40,-20
-- Added the last row to test correct result for each date
go
I think the following query will return the results you're after:
SELECT a.Account, a.TransDay,
(SELECT SUM(Amount)
FROM Trans AS b
WHERE b.Account = a.Account
AND b.TransDate >= a.TransDay
AND b.TransDate < DATEADD(day, 1, a.TransDay)) AS Amount,
a.Balance
FROM (SELECT c.Account, c.Balance,
DATEADD(day,
DATEDIFF(day, '20000101', c.TransDate),
'20000101') AS TransDay
FROM Trans AS c
WHERE c.TransDate = (SELECT MAX(d.TransDate)
FROM Trans AS d
WHERE d.Account = c.Account
AND DATEDIFF(day,
c.TransDate,
d.TransDate) = 0)) AS a
go
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Thank all for the help you provided. I used your inputs and could at
last get it to work.
*** Sent via Developersdex http://www.examnotes.net ***

Friday, March 23, 2012

Running Total cursor

I have two tables. ID table that has these fields
Code_id,YearPeriod, ReachedDate fields. And table
Amount that has Code_id,Amount,Date fields. What I
need to do is write a cursor that when the
amount.Amount adds up to $100.00 it Updates the
ReachedDate in the ID table to the amount.date fields
value of that record. Any help would be greatly appreciated.

You shouldn't need a cursor. Try this instead,
first create a view to give the totals up to
the current date.


CREATE VIEW AmountTotals
AS
SELECT a.Code_id,
a.Amount,
a.Date,
(SELECT SUM(b.Amount)
FROM Amount b
WHERE a.Code_id=b.Code_id
AND b.Date <= a.Date) AS RunningTotal
FROM Amount a
GO


Now you can update all of your ReachedDates
using this view


UPDATE ID
SET ReachedDate=(SELECT MIN(Date)
FROM AmountTotals
WHERE RunningTotal >= 100
AND AmountTotals.Code_id=ID.Code_ID)


|||

you have to create a for update, insert, delete trigger on

table amount which shall automatically mark the flag when the amount is reached. trigger fires automatically

|||Hey Mark. Works like a charm. Thank you so much.|||

Yeah, right. And freeze the server like magic! The best and faster solution its using cursors. I can say because I use "the magic" in some points of my app, and Im having performance problems with it.

Its really sad that microsoft dont release real solutions for simple problems like that.

Running Total cursor

I have two tables. ID table that has these fields
Code_id,YearPeriod, ReachedDate fields. And table
Amount that has Code_id,Amount,Date fields. What I
need to do is write a cursor that when the
amount.Amount adds up to $100.00 it Updates the
ReachedDate in the ID table to the amount.date fields
value of that record. Any help would be greatly appreciated.

You shouldn't need a cursor. Try this instead,
first create a view to give the totals up to
the current date.


CREATE VIEW AmountTotals
AS
SELECT a.Code_id,
a.Amount,
a.Date,
(SELECT SUM(b.Amount)
FROM Amount b
WHERE a.Code_id=b.Code_id
AND b.Date <= a.Date) AS RunningTotal
FROM Amount a
GO


Now you can update all of your ReachedDates
using this view


UPDATE ID
SET ReachedDate=(SELECT MIN(Date)
FROM AmountTotals
WHERE RunningTotal >= 100
AND AmountTotals.Code_id=ID.Code_ID)


|||

you have to create a for update, insert, delete trigger on

table amount which shall automatically mark the flag when the amount is reached. trigger fires automatically

|||Hey Mark. Works like a charm. Thank you so much.|||

Yeah, right. And freeze the server like magic! The best and faster solution its using cursors. I can say because I use "the magic" in some points of my app, and Im having performance problems with it.

Its really sad that microsoft dont release real solutions for simple problems like that.