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.
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 have a parameter date from dataset date:
Sample of data
Key
Month
Year
Row num
20210131
January
2021
3
20201231
December
2020
2
20201130
November
2020
1
I need to do an expression that returns the previous of selected value for example when a user selects January 2021(date parameter) it will return December 2020 in expression in text box.
I try previous(first(fields! Month_year. Value, "group name")) but it returns error, is there any way to resolve it?
I would suggest that you extend the dataset query to include the previous value against each row.
Assuming you dataset query is called DataSet1 and uses a table called 'myTable' then something like this (I changed the sample column name from Key to KeyID to avoid keyword problems).
SELECT *
, LAG(KeyID) OVER(ORDER BY RowNum) as PreviousMonthKeyID
FROM myTable
NOTE: This assumes row number is always in the correct order, if not then you could change this to order by KeyID.
You can then use a LOOKUP() to find the correct value, so if your parameter is called selectedDate and it's value is set to the KeyID column, use something like
=LOOKUP(Parameters!selectDate.Value, Fields!KeyID.Value, Fields!PreviousMonthKey.Value, "DataSet1")
This reads "get the value in selectdDate, find this value in the column KeyID in the dataset called DataSet1 and return the value found in the column called PreviousMonthKeyID"
At SSRS, one of my reports have date range as parameter - From Date (#FD) and To Date (#TD), these two parameters pass at query for the report to generate
At SSRS the parameter is of date/time type, I'm looking for a solution whereby when user select a date range it should include the time factor as below
if the user has selected say, FD 01/09/2018 and TD 30/09/2018 from report date picker
then I want the parameter to pass as 2018-09-01 00:00:00.000 and 2018-09-30 23:59:59.000 to the query. This 00:00:00.000 and 23:59:59.000 as a fixed range suffix to date.
How to achieve it?
I was trying combinations, this one i found working sort of.. got some clues for many forum
declare #FFD datetime2
declare #TTD datetime2
set #FFD = cast ('2018-09-01' as DATE)
set #TTD = DATEADD(s, -1, DATEADD(S, 86400, '2018-09-30'))
print #FFD
print #TTD
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.
How can I write an MDX statement or query that selects the clients who paid last month but have not paid this(Current Month) month?. I have a data cube designed and deployed on Microsoft SQL Server Analysis Services R 2. I have a customer dimensions and a fact table.
Please help.
I assume you have a [Time] dimension, and a measure that contains a value if the client has paid. I think the Filter() function will help you reduce a set of all clients down to just the clients that you're interested in.
SELECT {Filter({[Client].[SomeLevel].members}, ([Time].[LastMonth], [Measures].[whatever]) > 0 AND ([Time].[ThisMonth], [Measures].[whatever]) = 0} ON ROWS, {[Measures].[whatever]} ON COLUMNS FROM [CubeName]
You trouble might be deciding what to use in place of where I wrote [Time].[ThisMonth] - see other answers here on StackOverflow for selecting 'current' dates.
First of all, you have to identify the current month and the last month. One way to do it is compute it using the VBA!Date function.
So if your dates are stored in the format 12/31/2014 and assuming you have a measure Payment and a Date dimension with a Year-Quarter-Month-Date hierarchy, the below code can help you.
WITH MEMBER [Measures].ValueThisMonth AS
(
[Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT,
[Measures].[Payment]
)
MEMBER [Measures].ValueLastMonth AS
(
[Date].[Year-Quarter-Month-Date].CURRENTMEMBER.PARENT.LAG(1),
[Measures].[Payment]
)
SELECT [Client].[Client Name].MEMBERS
HAVING ISEMPTY([Measures].ValueThisMonth)
AND NOT(ISEMPTY([Measures].ValueLastMonth))
ON 0
FROM [Your cube]
WHERE
StrToMember("[Date].[Year-Quarter-Month-Date].[Date].&[" + FORMAT(VBA![Date](), "MM/dd/yyyy") + "]" + "]")
If instead you would like to pass this "current" value from the front end, use a parameter in the WHERE clause.