I am Working on an SSRS report. I have a dataset with the following data points: salesid, items, amount, date.
#start_date and #end_date are the two report parameters.
I have created a textbox (Sum(sale) from #Start_date to #end_date ) now I want to create a text box for (Sum(sales) for the #start_date(previous) to #end_date(previous) month.
Thanks
I would think that if you are not applying the parameters to your query so that you get all the data back... you just change the summation query to be: sum(sales) with parameters using expressions and the expression being: =DateAdd("M",-1,Parameters!start_date.value) or something very close to that expression.
Related
I am trying to create a query in Access that sums the number of Projects Under Consideration and Development as a Month End Inventory. There are three fields I need to get that number dtCreate, dtLegalEnd, and dtFinalClosed, but I also need the code to be dynamic so that it can pull that same sum for a give month, months and years after it has passed. So I tried to do it has a nested IIF parameter query with the following syntax:
SELECT sum(IIF([tblProjectsA].[dtCreate]>[Enter Date End of Month],0,sum(IIF([tblProjectsA].[dtLegalEnd]>[Enter Date End of Month] or is null,0,Sum(IIF([tblProjectsA].[dtFinalClosed]>[Enter Date End of Month] or is null,0,1))))))
FROM tblProjectsA;
Where is my syntax error(s)? Is there a better way to achieve the same result or have the results for each mm/yyyy query?
Thanks,
Meg
Try
SELECT sum(IIF([tblProjectsA].[dtCreate]>[Enter Date End of Month],0,sum(IIF([tblProjectsA].[dtLegalEnd]>[Enter Date End of Month]
or [tblProjectsA].[dtLegalEnd] is null,0,Sum(IIF([tblProjectsA].[dtFinalClosed]>[Enter Date End of Month] or [tblProjectsA].[dtFinalClosed] is null,0,1)))))) FROM tblProjectsA;
As for having results for each mm/yyyy, you should use GROUP BY clause, like
SELECT Month([your date]) AS Month, Year([your date]) AS Year, ...
FROM ...
GROUP BY Month([your date]), Year([your date])
The error is caused because you are summing a sum. Sum is an sql function that if Sum(column) where column has 5 rows that all = 1, then Sum will return 5. When you try to call sum inside sum Access doesn't officially know what column to pass to the inner sum to get a value to put in the outer sum. So Access throws an error, you can tell access to calculate the inner sum first by wrapping it in a subquery.
But I find subqueries are harder to understand and don't have good Access designer support. So instead I use calculated fields which I find more intuitive and declaritive.
ProjectUnderConsideration: IIf(([dtCreate]<[MonthEnd]) And ([dtFinalClosed]<[MonthEnd]) And (([dtLegalEnd]<[MonthEnd]) Or IsNull([dtLegalEnd])),1,0)
I don't understand the construct of ProjectUnderConsideration. Adjust this explanation to your actual case. I assumed a project is under consideration if dtCreate, dtLegalEnd, and dtFinalClosed are all < MonthEnd. and for demonstration I assumed dtLegalEnd could be null.
You can use the Designer in Access to help you write and test your sql:
'sql
PARAMETERS MonthEnd DateTime;
SELECT tblProjectsA.dtCreate, tblProjectsA.dtLegalEnd, tblProjectsA.dtFinalClosed, IIf(([dtCreate]<[MonthEnd]) And ([dtFinalClosed]<[MonthEnd]) And (([dtLegalEnd]<[MonthEnd]) Or IsNull([dtLegalEnd])),1,0) AS ProjectUnderConsideration
FROM tblProjectsA;
Now we have a ProjectUnderConsideration Column to sum. Change the query to a totals query:
PARAMETERS MonthEnd DateTime;
SELECT Sum(IIf(([dtCreate]<[MonthEnd]) And ([dtFinalClosed]<[MonthEnd]) And (([dtLegalEnd]<[MonthEnd]) Or IsNull([dtLegalEnd])),1,0)) AS ProjectUnderConsideration
FROM tblProjectsA;
I see a mystery behaviour in my *.rdl. I have 2 datasets defined.
I have 4 parameters defined,
StartDate,EndDate, companyid, sitecode
For both datasets,I have defined a select query.
DatasetA uses #Enddate
DatasetB not using it( it uses, startdate, companyid, sitecode)
I want to getrid of #EndDate from datasetA too. So, im using #startdate parameter to define enddate and using that in my sql query.
eg :
DECLARE #eDate AS date =EOMonth(#StartDate)
But after getting rid of this, #EndDate, my second data retrieves less data.(ie: if it should return data from september and october, now it returns only from September)
I checked the rdl, rowgroup/column group everywhere, but there is no any filter defined like that. I see this behaviour, only if i change #EndDate parameter from 1st dataset.
eg:
DECLARE #eDate AS date =EOMonth(#StartDate)
Select ..
Where date>=#StartDate AND date<=#Enddate to date<=#eDate
Is there any place we use parameter as a filter check? If so, how can I check it, where it has been used in the *.rdl?
I figured out the issue. This is due to Lookup function I use between both datasets. So, when dataset2 is trying to retrieve the correct number of rows, dataset1 was controlling it, becuase it didnt return rows for that date.
eg: dataset1 returns September data, while dataset 2 returns September+October data.
Due to lookup function, Dataset1 controls the dataset2's October data.
So I have an SSSRS REPORT with 2 data sets. If the day of the week is Friday I need to show the data in dataset 2 otherwise to use dataset 1. How can I accomplish this? is there a built in expression or function to do this???
You can't set DataSetName property at runtime, but you can select the data you want to return in your dataset based on the week day.
IF DATENAME(WEEKDAY,GETDATE()) = 'Friday'
select categoryDS1 Category, salesDS1 Sales from tableDS1
ELSE
select categoryDS2 Category, salesDS2 Sales from tableDS2
This will work if both SELECT statements have the same columns name
and types.
Let me know if this helps.
You can place a copy of both reports in the report and simply set the visibility for the one you want to show. The expression for the Visibility property for DataSet1 would be:
=IIf(WeekdayName(Weekday(Today)) = "Friday", True, False)
Swap the result for DataSet2.
I've a column with values for each month of the year.
Then in parameters of my report i would be able to set the month.
SSRS should return this column with values for each month of the year (like if there's no parameter) but the sum at the bottom of this column should return the sum of the value from the beginning of the year to the selected month.
Is it possible?
Yes. If I'm understanding correctly, you want something like the image below:
Assuming your MonthYear column is a DateTime and your month parameter is an Integer, you can use an expression like the following to conditionally sum the total based on the parameter value:
=Sum(IIf(Month(Fields!MonthYear.Value) <= Parameters!Month.Value, Fields!Value.Value, 0))
I have an SSRS report which gets filtered with the following expression:
="{[Claim Cheque].[Cheque Date].&[" + format(Parameters!StartDate.Value, "yyyy-MM-dd") + "T00:00:00]:[Claim Cheque].[Cheque Date].&[" + format(Parameters!EndDate.Value, "yyyy-MM-dd") + "T00:00:00]}"
which works fine. My problem is I don't have cheques everyday and this makes the query return no results. As an example I'm choosing the date range from 1st to 20th of November. I have cheques in 14th and 15th but NOT 20th. I will miss 14th and 15th results in my report this way.
I know how to force the parameters to get only existing values in the cube. but I need to be able to select all dates. Is there any other way to make this expression return desired results?
Any help is appreciated.
It looks to me like you have a separate date dimension just for [Cheque Date], rather than linking back to a fully populated master date dimension. Take a look at the way Order Date and Ship Date dimensions are done in the AdventureWorks sample. They are explained nicely here: Role-playing dimensions
I was able to run MDX queries like yours against that data, where there were no transactions on the start and end dates of the range:
Select
[Measures].[Order Count] on 0,
[Sales Channel].&[Reseller] on 1
From [Adventure Works]
Where {[Ship Date].[Fiscal].[Date].&[20060701]:[Ship Date].[Fiscal].[Date].&[20060710]}
and
Select
[Measures].[Order Count] on 0,
([Sales Channel].&[Reseller],
{[Ship Date].[Fiscal].[Date].&[20060701]:[Ship Date].[Fiscal].[Date].&[20060710]}) on 1
From [Adventure Works]