Showing posts with label report. Show all posts
Showing posts with label report. Show all posts

Tuesday, March 27, 2012

Calculated Measures not showing in SSRS.

Hi,
I have two cubes , One is fairly large Cube and the other one is Smaller one.
When I try to Use SSRS to report on these two cubes, i could see the calculated measures only in the Smaller Cube and there are no such things in the Large Cube.
I could Report on the Large Cube with base Measures.
I see the below message at the end of the Measures List.
"More Measures Exists than can Be shown."

Am i missing something?
Can anyone point me to some clue .

Thankyou
Vidya

Hi,

did you reprocess the large cube after,adding the calculated measures?

|||

I have not used SSRS yet, but I came accross a similar issue when I was creating a cube.

When you create a cube on SSAS, it automatically creates a script called "CALCULATE." You can view it on Caluculation tab on the cube design. It contains the following code:

/*

The CALCULATE command controls the aggregation of leaf cells in the cube.

If the CALCULATE command is deleted or modified, the data within the cube is affected.

You should edit this command only if you manually specify how the cube is aggregated.

*/

CALCULATE

If this script is modified or deleted, you may not see your measures correctly in your cube.

|||Thankyou for the Reply,
But I Have that CALCULATE untouched.
Another intresting note is that i can see all the calculated measures with the values from EXCEL 2007.
When i try querying the cube for the Calculated Measure then i am getting the values ; Only problem is that i am not able to see them through SSRS.
I have tried re-processing the Cube but no luck.
Thankyou
vidya

Calculated measures in report builder

Has anyone been able to get time calculations to show up in Report Builder? I'm using the BI Wizard standard calculations for YTD & Period over period growth, but I can't figure out how to use them within Report Builder. They are available in Report Designer, however. I did find the info about assigning the calculations to a measure group. I tried that, but it didn't have any affect.

Any help is appreciated.

You can't. The Report Builder doesn't fetch dimension calculated members. For this reason, we abandoned dimension calculated members and defined them as calculated measures in the cube. I wasn't successful also in trying to define the calculated dimension members as regular members by implementing an utility dimension because cells that do not exists in the cube cannot be written to.|||

Thanks for your response, Teo.

Are you saying that you couldn't do it at all, or that you were able to convert the time calcs to calculated measures and you were then able to use them in Report Builder? At the moment I'm not sure how I would go about converting the time calcs to calculated measures.

BTW, I read your book. Nice work!

|||

Thanks. The calculated mesures approached worked but you will end up with as many calculated measures as the number of the time-based calculations (QTD, YTD, etc.). Another issue you will discover if you decide to take this road is that a date filter in the RB report won't overwrite the default member fo the Date dimension. This will force you to always bring the Date dimension in the report if the report uses the time calculated measures.

What I wasn't able to do is implement the Time intelligence dimension calculated members as regular members of an utility dimension.

It will be great if you could log this issue to connect.microsoft.com. The more it is asked for the more likely will be to get implemented.

|||

Hi,

I want to generate Ad-Hoc reports using report builder with cube created. But am not able to see any calculated measures in the report. Can anyone tell me how to solve this.

|||You need to assign the calculated measures to display folders using the Properties window on the Calculations tab.sql

Sunday, March 25, 2012

Calculated Fields in an OLAP cube severly impact data retrieval time

I have a OLAP cube that I'm using for a data source that has several
calculated measures in it. When I add the calculated measures to my report
the retrieval time goes from ~1 second to ~4 minutes. I haven't been able
to locate any information about this issue. Is there something I'm doing
wrong, or is this a Reporting services issue?Nevermind. I hadn't realized that splitting a calculated field over an
unrelated dimension would have the same effect.
"Jeremy Farnham" <jeremy.farnham@.omya.com> wrote in message
news:esFYjweBIHA.4712@.TK2MSFTNGP04.phx.gbl...
>I have a OLAP cube that I'm using for a data source that has several
>calculated measures in it. When I add the calculated measures to my report
>the retrieval time goes from ~1 second to ~4 minutes. I haven't been able
>to locate any information about this issue. Is there something I'm doing
>wrong, or is this a Reporting services issue?
>sql

Calculated Fields

I have two questions regarding calculated fields.
I have a report with two datasets.
Issue 1:
Dataset 1 queries a table that contains configuration information. This
table has one row.
I would like to create a calculated field that divides the value of a
column in this one row but another value in the one row. The problem
appears to be that SRS is expecting the query to return 1 or more rows,
and thus only likes to let me do aggregations on the output from the
dataset. Is there a way to either tell it that there will only be one
row, or a different way to extract the config info from the database
that makes more sense?
Issue 2:
I would then like to use the output of the calculated field from issue
one as part of a calculated field in the second dataset. This seems to
be a problem, as SRS complains with the following statement:
=Sum(Fields!INVOICEAMOUNT.Value, "DailySalesDS") /
Fields!DailyInvoiceProRateMultiplier.Value, "InputDataDS"
Will not compile. I get errors regarding aggregates in report
parameters and about using something from another dataset.
My guess is that I am going about this the wrong way. Any help is
appreciated.In case you missed it, I have answered your questions already in the
"Computed Fields/Multiple Datasources" thread yesterday.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Hunter Hillegas" <hunter.hillegas@.gmail.com> wrote in message
news:chtc25$sd9@.odbk17.prod.google.com...
> I have two questions regarding calculated fields.
> I have a report with two datasets.
> Issue 1:
> Dataset 1 queries a table that contains configuration information. This
> table has one row.
> I would like to create a calculated field that divides the value of a
> column in this one row but another value in the one row. The problem
> appears to be that SRS is expecting the query to return 1 or more rows,
> and thus only likes to let me do aggregations on the output from the
> dataset. Is there a way to either tell it that there will only be one
> row, or a different way to extract the config info from the database
> that makes more sense?
> Issue 2:
> I would then like to use the output of the calculated field from issue
> one as part of a calculated field in the second dataset. This seems to
> be a problem, as SRS complains with the following statement:
> =Sum(Fields!INVOICEAMOUNT.Value, "DailySalesDS") /
> Fields!DailyInvoiceProRateMultiplier.Value, "InputDataDS"
> Will not compile. I get errors regarding aggregates in report
> parameters and about using something from another dataset.
> My guess is that I am going about this the wrong way. Any help is
> appreciated.
>sql

Calculated field when export to excel > number as text

In my report, I have a calculated field which when exported to excel
shows up as text with the smart tag message 'number as text'. I have
tried all formatting strings as part of the calculated expression
CDbl, Cdec, Int, FormatCurrency etc ... but the 'number as text' does
not seem to go away.
How can I export the calculated field results to excel 2007 from SSRS
as number and not as text.
Please help.
Thank you for your time!I have this same issue! Have you determined how to fix this? dhughes@.cogc.com
"avididy" wrote:
> In my report, I have a calculated field which when exported to excel
> shows up as text with the smart tag message 'number as text'. I have
> tried all formatting strings as part of the calculated expression
> CDbl, Cdec, Int, FormatCurrency etc ... but the 'number as text' does
> not seem to go away.
> How can I export the calculated field results to excel 2007 from SSRS
> as number and not as text.
> Please help.
> Thank you for your time!
>|||Hi,
Did you find a solution to the problem of calculated fields appearing as
text in Excel?sql

Thursday, March 22, 2012

Calculated field in Footer...running total

Hello,

How do I add unique values on the report? For example say I have this in my report:

Customer: Food Purchased: Amount:

Judy Cat Food $12

Sarah Dog Food $13.50

Diane Rabbit Food $17

Jason Dog Food $16

Tammy Dog Food $15

In the footer of the report I want to print a summary box that looks like this:

Product: Number Purchased: Total:

Cat Food 1 $12

Dog Food 3 $44.50

Rabbit Food 1 $17

How do I do this?

Thanks!

group on the food purchased fields and do a count on the group.|||

I'm not an expert at this. It is easy to say what do to. Can you tell me how to do it?

|||

Hello,

I don't think there is a way to have a summary like that in the footer of your report. But this will add your group totals, then you can just hide the details if you need.

Right click on the row handle for your detail row and select 'Insert Group'. In the box that pops up, give the group a name (or leave the default), select the Food Purchased field as your expression and select the box for 'Include group footer'. This will create two new rows in your table, a header and footer. In one of your footers textbox's, enter this to get the count of the group:

=CountRows()

If you don't want to see the details and just want the summary, click the row handle and change the Visibility -> Hidden propery to True. This will hid your details and only show the group footers.

Hope this helps.

Jarret

|||I have one question if the data of your main report is not fit in one page then the footer will repeat on next page. Does it ok with your requirement ?|||

I am converting this report from a crystal report. So yea, in the report now it is in a Report Footer and it only appears on the last page. This is how I need it because I was told to make the SQL Report look exactly like the CR. Unfortunately it seems like SRS doesn't give you a really nice option of doing Running Total fields like in Crystal. In Crystal they created a running total field and said "count all that are Dog Food" and then another running total that said "Count all that are Cat Food." I am not sure if putting it on the group footer will work because I need the report to display as it is. And to just say =CountRows() seems like it will count all rows and return 5. But I haven't tried it.

I created another report and put all the footer stuff in a table footer. And the table footer only appeared on the last page. I would like to put all this information in the table footer not the report footer. Sorry if I didn't explain that too well.

I am very surprised that SRS doesn't have an easy way to do this.

|||

Hello,

Using =CountRows() will give you the number of rows in that scope, so if you put this in your group header/footer, it will show the number of rows in that group. If you place it in the table header/footer, you will get the total number of rows in the table.

Jarret

|||

How do I put the conditional on? Currently it is counting all rows in the database for each type of food. What if I want to say "only count the rows that are on the report" (or only records that happened in the past week)?

|||

This worked in the table footer!

=Count(iif(Trim(Fields!FoodPurch.Value)="Dog Food",Fields!FoodPurch.Value, Nothing))

Calculated field in dataset using Previous() function

Hi,
Iam trying to add a calculated field to my report dataset which based on
value of a field in the previous row. The calculated field is defined as
=IIf(Previous(Fields!Col1.Value)=Fields!Col1.Value,0,CDbl(Fields!Col2.Value)+CDbl(Fields!Col3.Value))
. Iam basically checking the value of Col1 in previous row with value in
current row. Iam getting the following error when tried to build the report
"An internal error occurred on the report server. See the error log for more
details.". I could not find anything in error log.
Can anyone help in resolving this problem ?
Thanks,
RKOn Dec 3, 1:35 am, "S V Ramakrishna"
<ramakrishna.seeth...@.translogicsys.com> wrote:
> Hi,
> Iam trying to add a calculated field to my report dataset which based on
> value of a field in the previous row. The calculated field is defined as
> =IIf(Previous(Fields!Col1.Value)=Fields!Col1.Value,0,CDbl(Fields!Col2.Value-)+CDbl(Fields!Col3.Value))
> . Iam basically checking the value of Col1 in previous row with value in
> current row. Iam getting the following error when tried to build the report
> "An internal error occurred on the report server. See the error log for more
> details.". I could not find anything in error log.
> Can anyone help in resolving this problem ?
> Thanks,
> RK
I found that the Previous(Fields!XYZ.Value) function only works in the
Table and Matrix expressions -- expresions that are evaluated at
render time. Although it would make sense to have them in the DataSet
as a calculated field, I've not been able to get this to work.
Oracle has LAG and LEAD functions that return the previous/next value
of a Field as part of the query results. Microsoft T-SQL does not
have an equivalent.
-- Scottsql

Calculate Yearly Sales Difference

Hello,
I've been using Crystal Reports a little bit for about a year now, but have never created a report like this.

The report I am working on displays:
CUSTOMER
2005 SALES $000000.00
2006 SALES $000000.00
TOTAL SALES $000000.00
$ DIFFERENCE $000000.00
% DIFFERENCE $000000.00

I am able to bring up the yearly sales and total sales, but I cannot figure out how to calculate the difference. Any help will be greatly appreciated.

Thank you.I think you must create a query in command query in database expert:
one command query for select sum(sales) from tablename where year=2005 group by year... also another command query for 2006 and compute the difference between the two field in report using formula.

i know it is not nice suggestion but if you have no other idea then try this.|||Thanks for the idea.
I'll take a look and see if I can get it to work.sql

Calculate Unit % by Category

I have a report that is grouped by Category and on each detail line I need to show the % Units Sold per Category. I can't figure out how to get the total Units Sold per Category before I write the individual lines. Can someone, please, walk me through this process?

Thank you very much!!!

ChrisRight click on the filed select summary and summary type as sum and Check the button "show as Percentage" and select again the filed

Calculate Total Column

I need to calculate the Average by Location and then sum the Average for a Total that is displayed on a report. Following is my stored procedure so far:

SELECT tblLocn.LocnCode, tblLocn.LocnDesc,
#work.StartDate, #work.ZValue,
J1.ZAvg ............. Average by locn -- want the sum of all locns here
FROM tblLocn
LEFT JOIN #work ON tblLocn.LocnCode = #work.LocnCode
LEFT JOIN (SELECT #work.LocnCode,
ZAvg = Avg(#work.ZValue)
FROM #work
GROUP BY #work.LocnCode) J1 ON tblLocn.LocnCode = J1.LocnCode

How would I change this procedure to display either a) total average on each row, or b) location average on 1 row only so when I Sum this field it is the correct value.
I am aware that I could create a workfile with the Total value and then Join to that. Is there another alternative? ThanksJ1.ZAvg is your average by location, so when you sum it on a report you will get the sum of all averages.

Bigger question: are you sure this the operation you want? Your statistics will be skewed if your location don't have equal number of records. Consider:
Sum(Avg(1,2,3,4,5), Avg(6,7,8)) = 10

But the same values distributed across different locations yields this:
Sum(Avg(1,2,3), Avg(4,5,6,7,8)) = 8

If you just want the average per location, this value is constant across all locations since it applies to the entire enterprise, and can be calculated separately:
Sum(#work.ZValue)/Count(Locations)

blindman|||I do want the average by location as I have it coded. The problem with just summing the J1.ZAvg field is that the SELECT statement is not grouped by location but rather by DATE. This means that the J1.ZAvg field appears on each row for the location. If I sum that up, I would get an exploded value. Make sense?|||If I change the J1.ZAvg to Sum(J1.ZAvg), that would give me the total I want, except that it seems I cannot use the Sum unless I use a GROUP BY clause. In Access I used the DSUM aggregate function which is not available for Access Project. I may be missing something as I'm fairly new to SQL Server.|||So calculate the value once, store it in a variable, and include it in your output select statement:

set @.SumLocationAvgs = sum((select avg(zwork) from #Workd group by location))

Note: the above is just pseudo-code. You'll have to write for your specification.

blindman|||Makes total sense! Thanks a bunch.|||Oops .. I get the following message:

ERROR 130: Cannot perform an aggregate function on an expression containing an aggregate or a subquery

Set @.SumLocationAvgs = Sum((SELECT Avg(#work.ZValue) FROM #work GROUP BY LocnCode))|||Try this instead:

Set @.SumLocationAvgs =
(select Sum(SubQuery.LocnCodeAvg)
from (SELECT Avg(#work.ZValue) LocnCodeAvg FROM #work GROUP BY LocnCode) SubQuery)|||Exactly what I needed. Thank you.

Tuesday, March 20, 2012

calculate percentage

I have a report in which there is a column callled "Login Status".The values in the Login Status column can be 'Available','Successful' and 'Error'.
I am able to get the count for each options.
For example i have a table that has 10 rows.
I am able to get number of rows that have Login Status ="Available" and so on.I am getting this using Running Total Fields.
Now i want to calculate the percentage of each options.
For example there are 10 rows.
Available count=5
Successful count=3
Error=2
So Available Percent=Available Count*100/Total.
How can i achieve this calculation?
i am placing all Running Total Field in report footer
Thank you very much in advance
Regards
JigneshAdd a formula for each porcentage calculation and place them in report footer section

To get the total of records You can use the function RecordCount|||Also, read up on the PercentOf functions, which may be useful if you are grouping on status.sql

Calculate in report or in stored procedure

I have a requirement for two reports, which are basically except that one
shows values, whereas the other shows percentages. I would like to code this
as one report that modifies its display behaviour based on a parameter that
is passed in ( value 'P' or 'V').
The format of the cells in the grid will be an expression, giving integer
for values and one decimal place for percenatges.
If the percentages version is requested I can do the percentage calculation
in one of two places...
1. in the report with an expression against the cell Value.
2. in the stored procedure so that percentages are returned.
Which is best practice? If ReportingServices is running on the same SQL
Server as the source database is there a preference for overall performance?
Thanks,
AndrewHello Andrew,
Calculating in Report will run the calculating works in the
ReportingService process.
My suggestion is that you could calculating in the stored procedure which
is faster.
Also for the performance consideration, you could use the Report Cache.
Hope this helps.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||On Jun 4, 10:28 am, Duke (AN247) <D...@.newsgroup.nospam> wrote:
> I have a requirement for two reports, which are basically except that one
> shows values, whereas the other shows percentages. I would like to code this
> as one report that modifies its display behaviour based on a parameter that
> is passed in ( value 'P' or 'V').
> The format of the cells in the grid will be an expression, giving integer
> for values and one decimal place for percenatges.
> If the percentages version is requested I can do the percentage calculation
> in one of two places...
> 1. in the report with an expression against the cell Value.
> 2. in the stored procedure so that percentages are returned.
> Which is best practice? If ReportingServices is running on the same SQL
> Server as the source database is there a preference for overall performance?
> Thanks,
> Andrew
My personal preference is to do as much as possible in the stored
procedure. As far as performance gain, it depends on the size of the
returned dataset to the report and how complicated the expressions are
in the report. That said, you should be able to use some fairly simple
expressions to achieve the results you are looking for. So you could
use an expression similar to this in the Format property:
=iif(Parameters!ParameterName.Value = "P", #,0.0%, #,0)
Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||Thanks. I'd been leaning towards doing as much in the sproc as possible which
ties in with your answers. So, I'll calculate the percentage in the sproc
and the format in the report.
Cheers,
Andrew|||On Jun 5, 6:03 am, Duke (AN247) <D...@.newsgroup.nospam> wrote:
> Thanks. I'd been leaning towards doing as much in the sproc as possible which
> ties in with your answers. So, I'll calculate the percentage in the sproc
> and the format in the report.
> Cheers,
> Andrew
You're welcome. Let me know if I can be of further assistance.
Regards,
Enrique Martinez
Sr. Software Consultant

Monday, March 19, 2012

Calcaluting total nu of people based on their name field

I want to create a report which should be looked like this.

Members Joined Members Borrower Depositor Members Joined Yesterday 8 4 4 Members Joined Last 7 days 39 20 19 Members Joined Last 30 Days 243 120 122 Members Borrower Depositor 2007 Members Joined to Date 1,052 510 542 Q1-07 415 200 215 Q2-07 445 210 235 Q3-07 (To date) 192 100 92 All Members Joined 1,052 510 542

In the data base, there are some tables called members, loans and deposits containing members names, joined date , etc.

Example:

MembersTable

MemberName MemberID etc

LoansTable

MemberName CommencedDate

DepositorTable

MemberName CommencedDate

I assume that I should be able to create a report using matix format. But I want to clarify few things before I start. How do I calculate nu members? Data base tables contains only names of the members but not numbers. Other thing is how can I group members by perticular time periods as shown above? Do I need to use parameters? Also In the table, members can be borrowers or a depositors? How can clarify this one?

Please Can anyone give an idea? How to start and which direction I should go etc?

Thanks

I personally prefer to do all this work at the data layer within the SQL query rather than trying to get rs to SUM things conditionally.

Looking at your definition, I would creaste multiple datasets and probably stick to returning 3 columns in my dataset and using a table for the layout rather than a matrix as they are more flexible. This makes sense as your number of columns does not need to expand dynamically which is what a matrix is really meant for.

You should also consider whether you will add a date parameter to do "as at" queries or whether you will just use GETDATE() to get the current date and time.

|||

Thanks Adam I will try with a table. I think he wants to see the report once a month without querying. Run the report and get the results end of each month.

I wrote a query something like this.

SELECT COUNT(DISTINCT(Members.Name), COUNT(DISTINCT(Loan.Name) AS Borrowers. , COUNT(DISTINCT(Depositor.Name) AS Depositors

FROM Members M

INNER JOIN Loan L ON M.Name = L.Name

INNER JOIN Depositor D ON M.Name = D.Name

WHERE ( L.CommencedDate BETWEEN (@.Startdate) AND (@.GETDATE( ) )

AND

D.CommenceDate BETWEEN (@.Startdate) AND (@.GETDATE( ) ) )

Am I going right direction?

Thanks

|||

I'd break it up a bit and firstly try to write the queries for the individual bits of infrmation and look to see if you can bring them together.

by loking at your data, borrower + depositor = member, is it safe to assume that? If so then there's no need to join to member is there? or can member potentially be both?

Assuming the former,

Dataset1:

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'Members Joined Yesterday'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-1)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-1)

),

last7daysCTE AS

(

SELECT type = 'Members Joined Last 7 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-7)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-7)

),

last30daysCTE AS

(

SELECT type = 'Members Joined Last 30 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-30)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-30)

),

combinedCTE AS

(

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7daysCTE

UNION ALL

SELECT * FROM last30daysCTE

)

SELECT *

, members = borrowers + depositors

FROM combinedCTE

You can employ a similar startegy to construct the querters except you probably won't to have a separate CTE per quarter.

|||

Thanks lot for the codes Adam..Yes Total Number of members are sum of borrowers and depositors. But member can not be both. But from membertable we can not identify whether they are borrowers or depositors. I need to get that info from borrowers and depositors tables.

I tried with my codes. I had to change @.GETDATE as @.Enddate. Except that My code worked. But drawback is user has to input dates manually inorder to see that. I think the one you wrote does not requre user to enter dates. I will try with your code.

One more thing..what do u mean CTE?

Probably for 2007 year members statistics, I may need to make a seperate data set.

Thanks again

|||

Your code worked perfectly. Thats what exactly I want. I will write a similar code for 2007 qtrs too.

Thanks lot

|||

I wrote the code for quarters too.

I clicked new data set and then in the querry string window I wrote the query.

But when I click ok,it gives the following error message.

"Specify a CLS compliant name for the data set."

What does that mean?

Instead of GETDATE() , can I specify dates?

As a example;

commencementDate BETWEEN '01/01/2007' AND '03/31/2007'

When I do this , I get the error message.

|||well everything works well...Thanks for your help Adam|||

Glad I could help.

CTE stands for Common Table Expression and is a new addition to T-SQL 2005. I think they make code a lot more readable.

|||

ok..I have another problem which is almost similar.

CD - Table

Amount(int) StartDate(Date) AccountID(int)

I want to create a report from this table. the report should look like this.

Value No of Accounts Average Value

For Yesterday

For Last 7days

For Last 30 days

Can I use the same query..Here I have only one table. I assume I should be able to use it. I already wrote it. But there is a syntax error.

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, Values = (select sum( Amount )

from CD Table

where StartDate >= GETDATE()-1)

, No Of CDs Sold = (select count(AccountID)

from CD Table

where StartDate >= GETDATE()-1)

, AverageCD Size = (select avg(Amount)

from CD Table
where StartDate >=GETDATE()-1)

),

I get the following error message.

There is an error in the query. Incorrect syntax near the keyword 'Values'.
Incorrect syntax near ','.
Incorrect syntax near ','.
Incorrect syntax near ')'.

I dont know why? Can you please show me where I went wrong?|||

I'd like to help but your query does not resemble the above example, if you want column or table names to have spaces then you have enclose them in [] e.g. [AverageCD Size] instead of just AverageCD Size. Secondly, you should look up the syntax for a CTE and in this case you probably don't need one.

|||Yes I changed the startdate now. I tried with [ ] .But did not work. I looked at the syntax for CTE. As you said I dont need one. But still get the same error message.|||

Like I said, you're not giving me enough information to work with here.

shamen wrote:

Value(int) StartDate(Date) AccountID(int)

If these are the columns in your table then what is CDOrderFK doing in your query. Please be more explicit.|||I'm sorry CDOrderFK should be replaced with AccountID..Now it should be clear.|||

OK, I would still use the CTE, except you need to use 3 of them and the SQL can a be little simpler.

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-1

)

, last7days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-7

)

, last30days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-30

)

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7days

UNION ALL

SELECT * FROM last30days

Calcaluting total nu of people based on their name field

I want to create a report which should be looked like this.

Members Joined Members Borrower Depositor Members Joined Yesterday 8 4 4 Members Joined Last 7 days 39 20 19 Members Joined Last 30 Days 243 120 122 Members Borrower Depositor 2007 Members Joined to Date 1,052 510 542 Q1-07 415 200 215 Q2-07 445 210 235 Q3-07 (To date) 192 100 92 All Members Joined 1,052 510 542

In the data base, there are some tables called members, loans and deposits containing members names, joined date , etc.

Example:

MembersTable

MemberName MemberID etc

LoansTable

MemberName CommencedDate

DepositorTable

MemberName CommencedDate

I assume that I should be able to create a report using matix format. But I want to clarify few things before I start. How do I calculate nu members? Data base tables contains only names of the members but not numbers. Other thing is how can I group members by perticular time periods as shown above? Do I need to use parameters? Also In the table, members can be borrowers or a depositors? How can clarify this one?

Please Can anyone give an idea? How to start and which direction I should go etc?

Thanks

I personally prefer to do all this work at the data layer within the SQL query rather than trying to get rs to SUM things conditionally.

Looking at your definition, I would creaste multiple datasets and probably stick to returning 3 columns in my dataset and using a table for the layout rather than a matrix as they are more flexible. This makes sense as your number of columns does not need to expand dynamically which is what a matrix is really meant for.

You should also consider whether you will add a date parameter to do "as at" queries or whether you will just use GETDATE() to get the current date and time.

|||

Thanks Adam I will try with a table. I think he wants to see the report once a month without querying. Run the report and get the results end of each month.

I wrote a query something like this.

SELECT COUNT(DISTINCT(Members.Name), COUNT(DISTINCT(Loan.Name) AS Borrowers. , COUNT(DISTINCT(Depositor.Name) AS Depositors

FROM Members M

INNER JOIN Loan L ON M.Name = L.Name

INNER JOIN Depositor D ON M.Name = D.Name

WHERE ( L.CommencedDate BETWEEN (@.Startdate) AND (@.GETDATE( ) )

AND

D.CommenceDate BETWEEN (@.Startdate) AND (@.GETDATE( ) ) )

Am I going right direction?

Thanks

|||

I'd break it up a bit and firstly try to write the queries for the individual bits of infrmation and look to see if you can bring them together.

by loking at your data, borrower + depositor = member, is it safe to assume that? If so then there's no need to join to member is there? or can member potentially be both?

Assuming the former,

Dataset1:

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'Members Joined Yesterday'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-1)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-1)

),

last7daysCTE AS

(

SELECT type = 'Members Joined Last 7 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-7)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-7)

),

last30daysCTE AS

(

SELECT type = 'Members Joined Last 30 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-30)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-30)

),

combinedCTE AS

(

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7daysCTE

UNION ALL

SELECT * FROM last30daysCTE

)

SELECT *

, members = borrowers + depositors

FROM combinedCTE

You can employ a similar startegy to construct the querters except you probably won't to have a separate CTE per quarter.

|||

Thanks lot for the codes Adam..Yes Total Number of members are sum of borrowers and depositors. But member can not be both. But from membertable we can not identify whether they are borrowers or depositors. I need to get that info from borrowers and depositors tables.

I tried with my codes. I had to change @.GETDATE as @.Enddate. Except that My code worked. But drawback is user has to input dates manually inorder to see that. I think the one you wrote does not requre user to enter dates. I will try with your code.

One more thing..what do u mean CTE?

Probably for 2007 year members statistics, I may need to make a seperate data set.

Thanks again

|||

Your code worked perfectly. Thats what exactly I want. I will write a similar code for 2007 qtrs too.

Thanks lot

|||

I wrote the code for quarters too.

I clicked new data set and then in the querry string window I wrote the query.

But when I click ok,it gives the following error message.

"Specify a CLS compliant name for the data set."

What does that mean?

Instead of GETDATE() , can I specify dates?

As a example;

commencementDate BETWEEN '01/01/2007' AND '03/31/2007'

When I do this , I get the error message.

|||well everything works well...Thanks for your help Adam|||

Glad I could help.

CTE stands for Common Table Expression and is a new addition to T-SQL 2005. I think they make code a lot more readable.

|||

ok..I have another problem which is almost similar.

CD - Table

Amount(int) StartDate(Date) AccountID(int)

I want to create a report from this table. the report should look like this.

Value No of Accounts Average Value

For Yesterday

For Last 7days

For Last 30 days

Can I use the same query..Here I have only one table. I assume I should be able to use it. I already wrote it. But there is a syntax error.

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, Values = (select sum( Amount )

from CD Table

where StartDate >= GETDATE()-1)

, No Of CDs Sold = (select count(AccountID)

from CD Table

where StartDate >= GETDATE()-1)

, AverageCD Size = (select avg(Amount)

from CD Table
where StartDate >=GETDATE()-1)

),

I get the following error message.

There is an error in the query. Incorrect syntax near the keyword 'Values'.
Incorrect syntax near ','.
Incorrect syntax near ','.
Incorrect syntax near ')'.

I dont know why? Can you please show me where I went wrong?|||

I'd like to help but your query does not resemble the above example, if you want column or table names to have spaces then you have enclose them in [] e.g. [AverageCD Size] instead of just AverageCD Size. Secondly, you should look up the syntax for a CTE and in this case you probably don't need one.

|||Yes I changed the startdate now. I tried with [ ] .But did not work. I looked at the syntax for CTE. As you said I dont need one. But still get the same error message.|||

Like I said, you're not giving me enough information to work with here.

shamen wrote:

Value(int) StartDate(Date) AccountID(int)

If these are the columns in your table then what is CDOrderFK doing in your query. Please be more explicit.|||I'm sorry CDOrderFK should be replaced with AccountID..Now it should be clear.|||

OK, I would still use the CTE, except you need to use 3 of them and the SQL can a be little simpler.

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-1

)

, last7days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-7

)

, last30days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-30

)

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7days

UNION ALL

SELECT * FROM last30days

Calcaluting total nu of people based on their name field

I want to create a report which should be looked like this.

Members Joined Members Borrower Depositor Members Joined Yesterday 8 4 4 Members Joined Last 7 days 39 20 19 Members Joined Last 30 Days 243 120 122 Members Borrower Depositor 2007 Members Joined to Date 1,052 510 542 Q1-07 415 200 215 Q2-07 445 210 235 Q3-07 (To date) 192 100 92 All Members Joined 1,052 510 542

In the data base, there are some tables called members, loans and deposits containing members names, joined date , etc.

Example:

MembersTable

MemberName MemberID etc

LoansTable

MemberName CommencedDate

DepositorTable

MemberName CommencedDate

I assume that I should be able to create a report using matix format. But I want to clarify few things before I start. How do I calculate nu members? Data base tables contains only names of the members but not numbers. Other thing is how can I group members by perticular time periods as shown above? Do I need to use parameters? Also In the table, members can be borrowers or a depositors? How can clarify this one?

Please Can anyone give an idea? How to start and which direction I should go etc?

Thanks

I personally prefer to do all this work at the data layer within the SQL query rather than trying to get rs to SUM things conditionally.

Looking at your definition, I would creaste multiple datasets and probably stick to returning 3 columns in my dataset and using a table for the layout rather than a matrix as they are more flexible. This makes sense as your number of columns does not need to expand dynamically which is what a matrix is really meant for.

You should also consider whether you will add a date parameter to do "as at" queries or whether you will just use GETDATE() to get the current date and time.

|||

Thanks Adam I will try with a table. I think he wants to see the report once a month without querying. Run the report and get the results end of each month.

I wrote a query something like this.

SELECT COUNT(DISTINCT(Members.Name), COUNT(DISTINCT(Loan.Name) AS Borrowers. , COUNT(DISTINCT(Depositor.Name) AS Depositors

FROM Members M

INNER JOIN Loan L ON M.Name = L.Name

INNER JOIN Depositor D ON M.Name = D.Name

WHERE ( L.CommencedDate BETWEEN (@.Startdate) AND (@.GETDATE( ) )

AND

D.CommenceDate BETWEEN (@.Startdate) AND (@.GETDATE( ) ) )

Am I going right direction?

Thanks

|||

I'd break it up a bit and firstly try to write the queries for the individual bits of infrmation and look to see if you can bring them together.

by loking at your data, borrower + depositor = member, is it safe to assume that? If so then there's no need to join to member is there? or can member potentially be both?

Assuming the former,

Dataset1:

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'Members Joined Yesterday'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-1)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-1)

),

last7daysCTE AS

(

SELECT type = 'Members Joined Last 7 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-7)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-7)

),

last30daysCTE AS

(

SELECT type = 'Members Joined Last 30 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-30)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-30)

),

combinedCTE AS

(

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7daysCTE

UNION ALL

SELECT * FROM last30daysCTE

)

SELECT *

, members = borrowers + depositors

FROM combinedCTE

You can employ a similar startegy to construct the querters except you probably won't to have a separate CTE per quarter.

|||

Thanks lot for the codes Adam..Yes Total Number of members are sum of borrowers and depositors. But member can not be both. But from membertable we can not identify whether they are borrowers or depositors. I need to get that info from borrowers and depositors tables.

I tried with my codes. I had to change @.GETDATE as @.Enddate. Except that My code worked. But drawback is user has to input dates manually inorder to see that. I think the one you wrote does not requre user to enter dates. I will try with your code.

One more thing..what do u mean CTE?

Probably for 2007 year members statistics, I may need to make a seperate data set.

Thanks again

|||

Your code worked perfectly. Thats what exactly I want. I will write a similar code for 2007 qtrs too.

Thanks lot

|||

I wrote the code for quarters too.

I clicked new data set and then in the querry string window I wrote the query.

But when I click ok,it gives the following error message.

"Specify a CLS compliant name for the data set."

What does that mean?

Instead of GETDATE() , can I specify dates?

As a example;

commencementDate BETWEEN '01/01/2007' AND '03/31/2007'

When I do this , I get the error message.

|||well everything works well...Thanks for your help Adam|||

Glad I could help.

CTE stands for Common Table Expression and is a new addition to T-SQL 2005. I think they make code a lot more readable.

|||

ok..I have another problem which is almost similar.

CD - Table

Amount(int) StartDate(Date) AccountID(int)

I want to create a report from this table. the report should look like this.

Value No of Accounts Average Value

For Yesterday

For Last 7days

For Last 30 days

Can I use the same query..Here I have only one table. I assume I should be able to use it. I already wrote it. But there is a syntax error.

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, Values = (select sum( Amount )

from CD Table

where StartDate >= GETDATE()-1)

, No Of CDs Sold = (select count(AccountID)

from CD Table

where StartDate >= GETDATE()-1)

, AverageCD Size = (select avg(Amount)

from CD Table
where StartDate >=GETDATE()-1)

),

I get the following error message.

There is an error in the query. Incorrect syntax near the keyword 'Values'.
Incorrect syntax near ','.
Incorrect syntax near ','.
Incorrect syntax near ')'.

I dont know why? Can you please show me where I went wrong?|||

I'd like to help but your query does not resemble the above example, if you want column or table names to have spaces then you have enclose them in [] e.g. [AverageCD Size] instead of just AverageCD Size. Secondly, you should look up the syntax for a CTE and in this case you probably don't need one.

|||Yes I changed the startdate now. I tried with [ ] .But did not work. I looked at the syntax for CTE. As you said I dont need one. But still get the same error message.|||

Like I said, you're not giving me enough information to work with here.

shamen wrote:

Value(int) StartDate(Date) AccountID(int)

If these are the columns in your table then what is CDOrderFK doing in your query. Please be more explicit.|||I'm sorry CDOrderFK should be replaced with AccountID..Now it should be clear.|||

OK, I would still use the CTE, except you need to use 3 of them and the SQL can a be little simpler.

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-1

)

, last7days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-7

)

, last30days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-30

)

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7days

UNION ALL

SELECT * FROM last30days

Calcaluting total nu of people based on their name field

I want to create a report which should be looked like this.

Members Joined Members Borrower Depositor Members Joined Yesterday 8 4 4 Members Joined Last 7 days 39 20 19 Members Joined Last 30 Days 243 120 122 Members Borrower Depositor 2007 Members Joined to Date 1,052 510 542 Q1-07 415 200 215 Q2-07 445 210 235 Q3-07 (To date) 192 100 92 All Members Joined 1,052 510 542

In the data base, there are some tables called members, loans and deposits containing members names, joined date , etc.

Example:

MembersTable

MemberName MemberID etc

LoansTable

MemberName CommencedDate

DepositorTable

MemberName CommencedDate

I assume that I should be able to create a report using matix format. But I want to clarify few things before I start. How do I calculate nu members? Data base tables contains only names of the members but not numbers. Other thing is how can I group members by perticular time periods as shown above? Do I need to use parameters? Also In the table, members can be borrowers or a depositors? How can clarify this one?

Please Can anyone give an idea? How to start and which direction I should go etc?

Thanks

I personally prefer to do all this work at the data layer within the SQL query rather than trying to get rs to SUM things conditionally.

Looking at your definition, I would creaste multiple datasets and probably stick to returning 3 columns in my dataset and using a table for the layout rather than a matrix as they are more flexible. This makes sense as your number of columns does not need to expand dynamically which is what a matrix is really meant for.

You should also consider whether you will add a date parameter to do "as at" queries or whether you will just use GETDATE() to get the current date and time.

|||

Thanks Adam I will try with a table. I think he wants to see the report once a month without querying. Run the report and get the results end of each month.

I wrote a query something like this.

SELECT COUNT(DISTINCT(Members.Name), COUNT(DISTINCT(Loan.Name) AS Borrowers. , COUNT(DISTINCT(Depositor.Name) AS Depositors

FROM Members M

INNER JOIN Loan L ON M.Name = L.Name

INNER JOIN Depositor D ON M.Name = D.Name

WHERE ( L.CommencedDate BETWEEN (@.Startdate) AND (@.GETDATE( ) )

AND

D.CommenceDate BETWEEN (@.Startdate) AND (@.GETDATE( ) ) )

Am I going right direction?

Thanks

|||

I'd break it up a bit and firstly try to write the queries for the individual bits of infrmation and look to see if you can bring them together.

by loking at your data, borrower + depositor = member, is it safe to assume that? If so then there's no need to join to member is there? or can member potentially be both?

Assuming the former,

Dataset1:

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'Members Joined Yesterday'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-1)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-1)

),

last7daysCTE AS

(

SELECT type = 'Members Joined Last 7 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-7)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-7)

),

last30daysCTE AS

(

SELECT type = 'Members Joined Last 30 Days'

, borrowers = (select count(*)

from LoansTable

where CommencementDate >= GETDATE()-30)

, depositors = (select count(*)

from DepositorTable

where CommencementDate >= GETDATE()-30)

),

combinedCTE AS

(

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7daysCTE

UNION ALL

SELECT * FROM last30daysCTE

)

SELECT *

, members = borrowers + depositors

FROM combinedCTE

You can employ a similar startegy to construct the querters except you probably won't to have a separate CTE per quarter.

|||

Thanks lot for the codes Adam..Yes Total Number of members are sum of borrowers and depositors. But member can not be both. But from membertable we can not identify whether they are borrowers or depositors. I need to get that info from borrowers and depositors tables.

I tried with my codes. I had to change @.GETDATE as @.Enddate. Except that My code worked. But drawback is user has to input dates manually inorder to see that. I think the one you wrote does not requre user to enter dates. I will try with your code.

One more thing..what do u mean CTE?

Probably for 2007 year members statistics, I may need to make a seperate data set.

Thanks again

|||

Your code worked perfectly. Thats what exactly I want. I will write a similar code for 2007 qtrs too.

Thanks lot

|||

I wrote the code for quarters too.

I clicked new data set and then in the querry string window I wrote the query.

But when I click ok,it gives the following error message.

"Specify a CLS compliant name for the data set."

What does that mean?

Instead of GETDATE() , can I specify dates?

As a example;

commencementDate BETWEEN '01/01/2007' AND '03/31/2007'

When I do this , I get the error message.

|||well everything works well...Thanks for your help Adam|||

Glad I could help.

CTE stands for Common Table Expression and is a new addition to T-SQL 2005. I think they make code a lot more readable.

|||

ok..I have another problem which is almost similar.

CD - Table

Amount(int) StartDate(Date) AccountID(int)

I want to create a report from this table. the report should look like this.

Value No of Accounts Average Value

For Yesterday

For Last 7days

For Last 30 days

Can I use the same query..Here I have only one table. I assume I should be able to use it. I already wrote it. But there is a syntax error.

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, Values = (select sum( Amount )

from CD Table

where StartDate >= GETDATE()-1)

, No Of CDs Sold = (select count(AccountID)

from CD Table

where StartDate >= GETDATE()-1)

, AverageCD Size = (select avg(Amount)

from CD Table
where StartDate >=GETDATE()-1)

),

I get the following error message.

There is an error in the query. Incorrect syntax near the keyword 'Values'.
Incorrect syntax near ','.
Incorrect syntax near ','.
Incorrect syntax near ')'.

I dont know why? Can you please show me where I went wrong?|||

I'd like to help but your query does not resemble the above example, if you want column or table names to have spaces then you have enclose them in [] e.g. [AverageCD Size] instead of just AverageCD Size. Secondly, you should look up the syntax for a CTE and in this case you probably don't need one.

|||Yes I changed the startdate now. I tried with [ ] .But did not work. I looked at the syntax for CTE. As you said I dont need one. But still get the same error message.|||

Like I said, you're not giving me enough information to work with here.

shamen wrote:

Value(int) StartDate(Date) AccountID(int)

If these are the columns in your table then what is CDOrderFK doing in your query. Please be more explicit.|||I'm sorry CDOrderFK should be replaced with AccountID..Now it should be clear.|||

OK, I would still use the CTE, except you need to use 3 of them and the SQL can a be little simpler.

Code Snippet

WITH yesterdayCTE AS

(

SELECT type = 'CDs Sold Yesterday'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-1

)

, last7days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-7

)

, last30days AS

(

SELECT type = 'CDs Sold Last 7 Days'

, total_sales = sum(Amount)

, num_accounts = count(DISTINCT AccountID)
, average_sales = avg(Amount)

FROM [CD Table]

WHERE StartDate >= GETDATE()-30

)

SELECT * FROM yesterdayCTE

UNION ALL

SELECT * FROM last7days

UNION ALL

SELECT * FROM last30days