I am using SSRS 2015 to create a report. The data is sourced from a tabular cube so I used a DAX query to create the shared dataset. What I am trying to do is add parameters to my report which would allow users to filter the data according to their date range using the calendar picker. I tried:
EVALUATE
FILTER(
SUMMARIZE(
'PurchaseTable'
,'PurchaseTable'[Invoice Date]
),
'PurchaseTable'[Invoice Date] >= DATEVALUE(FORMAT(#FromDate, "dd/MM/yyyy"))
&& 'PurchaseTable'[Invoice Date] <= DATEVALUE(FORMAT(#ToDate, "dd/MM/yyyy"))
)
But it produced an error:
The following system error occurred: Type mismatch
I also tried:
'PurchaseTable'[Invoice Date] >= #FromDate
&& 'PurchaseTable'[Invoice Date] <= #ToDate
and get the following error:
DAX comparison operations do not support comparing values of type Date with values of type Text
My PurchaseTable[Invoice Date] column is of date type in dd/MM/yyyy format. Thank you in advance for any help.
If you are comfortable with adding parameters to DAX after playing around with SSRS, the following should be the code for your final DAX.
EVALUATE(
FILTER(
SUMMARIZE(
'PurchaseTable'
,'PurchaseTable'[Invoice Date]
),
'PurchaseTable'[Invoice Date] >= VALUE(#FromDate)
&& 'PurchaseTable'[Invoice Date] <= VALUE(#ToDate)
))
Make sure that your parameters are always of date type.
Hope this help?
Related
I am trying to create a query which will update a blank "To Date" field with the day prior to next updated date.
Example, an [Item Number] standard cost was updated ([From Date]) on 01/03/2019, then again on 01/07/2019 and then again on the 01/01/2020.
I would like an adjacent column which is updated with [To Date] of 30/06/2019, 31/12/2019.
I will run a subsequent query which updates blanks (i.e. current cost as there is no next [From Date]) to Today End of Month date (I assume I need a separate query for this rather than an IIF which can populate Blanks as part of this update query?)
Currently I have below, but it is updating the [To Date] with day prior to the newest date in all instances (i.e 31/12/2019 for first 2 rows), I understand that I need a SORT within the below query:
Many thanks in advance from this first time poster!
UPDATE
Standards
INNER JOIN
Standards AS Standards_1
ON
(Standards.[Item number] = Standards_1.[Item number]) AND (Standards.[From date] < Standards_1.[From date])
SET
Standards.[To Date 2] = Standards_1.[From date]-1;
This might work, but the performance migth be a bit slow:
UPDATE Standards
SET [To Date] = Nz(
DateAdd("d", -1,
DMin("[From Date]", "Standards", "[Item Number]=" & [Item Number] & " AND [From Date] > #" & [From Date] & "#")
)
, DateSerial(Year(Date()), Month(Date())+1, 0)
)
Start from the DMin function, which will lookup the next date greater than the current date for the item.
DateAdd function will subtract one day from this date.
Nz will use the value returned by the DateSerial function if the DateAdd function result is Null.
DateSerial function returns the end date of the current month.
# are added because of the date value of the [From Date] field in the criteria of the DMin.
Instead of using the [From Date] field in the DMin function criteria, you can consider using the Autonumber Primary Key field. You'll need to remove the # in the criteria.
Everything between Nz(...) will need to be on one line.
This solves both of your requirements, just test the performance.
I have a report of customers that I wish to run in SSRS. The report I want to return is for a particular period (e.g. 01/01/2016 and 29/02/2016). The parameter is against a date field (End_Date).
What I would like to return is a list of customers WHERE End_Date is either BETWEEN the dates above (or any other period) and WHERE End_Date IS NULL too.
I am able to create a parameter that will list customers with an End_Date between the dates I want but how do I also get the parameter to also list the NULL values.
Hopefully that's clear but just in case - I need a list of customers where End_Date is between two dates or NULL.
Thank you
You need to account for the possibility of a null in your evaluation using an OR for the END_DATE.
Are you using the parameter in the query or on the dataset? The SQL is a bit different that the SSRS expression.
SQL
WHERE DATE_FIELD >= #START_DATE AND (DATE_FIELD <= #END_DATE OR #END_DATE IS NULL)
SSRS
=IIF(Fields!DATE_FIELD.Value >= Parameters!START_DATE.Value AND (Fields!DATE_FIELD.Value <= Parameters!END_DATE.Value OR ISNOTHING(Parameters!END_DATE.Value), 1, 0)
In the other filter properties, set the type to Integer, Operator to =, and Value to 1.
This will evaluate the expression and return 1 if it matches and 0 if not - then it filters for the 1.
I am working on access I am stuck in a point.please help
i have a calculated field :
Sum(IIf(Format([Ref_Date],"yyyymm")
Between
Format(DateSerial(Year(Date()),1,1),"yyyymm")
And
Format(Date(),"yyyymm"),1,0))
it is calculating automatically but I have a report filter tool where I will select the date, now I need to pass that date range(that is: user date range) into this function so that it should work for any dates.
How can I achieve that?
You can create a function like this in VBA that will return true if the date is in the required range and you can then use that result to perform any other calculation.
Function InDateRange(RefDate As Date, StartDate As Date, EndDate As Date) As Boolean
If (RefDate >= StartDate) And (RefDate <= EndDate) Then InDateRange = True
End Function
You can use the function in the control source of a text box;
=IIF(InDateRange([txtRef],[txtStart],[txtEnd]),1,0)
where txtRef, txtStart and txtEnd are text boxes with the date values in.
I am a newbie to crystal reports, I have a crystal report for which I have a data source from which I am using some fields on to the report.
Crsytal Report Name : InventoryReport
Data Source : I am giving Stored Procedure -- GetInventoryData
Fields : ItemID, ShippedDate, ItemName
I have to get all items which are shipped in between FromData and ToDate of ShippedDate, so I am using formula {GetInventoryData;1.ShippedDate} in {?FromDate} to {?ToDate}
dataType of Shipped Date is String and I have to convert to Date as it needs to be compared but I am having issues in that...
ShippedDate value will be : 2011-04-19 16:02:14.0000000
I have to convert at crystal reports side only..
Please help me how can I cast it to date
actually even better don't use that formula .... in selection formula using the date range explained above
date(split({GetInventoryData;1.ShippedDate}," ")[1]) in {?daterange}
If you are using string, you may do a simple less-than or greater than like:
...where ShippedDate >= '2011-04-19 00:00:00' and ShippedDate <= '2011-04-19 23:59:59'
this is like:
...where ShippedDate >= '<from-date> 00:00:00' and ShippedDate <= '<to-date> 23:59:59'
This would work and you'll not have to cast to a date.
You may also use as (If it works for you):
...where ShippedDate >= '<from-date>' and ShippedDate <= '<to-date>'
one way ... create a formula called cvtDate
date(
tonumber(split({GetInventoryData;1.ShippedDate},"-")[1])
,
tonumber(split({GetInventoryData;1.ShippedDate},"-")[2])
,
tonumber(split({GetInventoryData;1.ShippedDate},"-")[3])
)
then instead of creating two date parameters.. create only one called daterange that allows range values under values options
Then selection formula would be
{#cvtDate} in {?daterange}
I would like to modify the Team Foundation Server built-in MS Agile template reports to exclude weekends.
For example, here is the dsWorkItemHistory dataset for the Remaining Work report:
WITH
MEMBER [Measures].[Date Key] AS
[Date].[Date].CurrentMember.UniqueName
SELECT
{
[Measures].[Date Key],
[Measures].[Cumulative Count]
} ON COLUMNS,
(
[Work Item].[System_State].[System_State],
(StrToMember(#StartDateParam):StrToMember(#EndDateParam))
)
ON ROWS
FROM [Team System]
WHERE
(
STRTOMEMBER("[Team Project].[Team Project].["+#Project+"]"),
STRTOSET(#IterationParam),
STRTOSET(#AreaParam),
STRTOSET(#WorkItemTypeParam)
)
I am totally unfamiliar with MDX. Any pointers toward customizing the data returned to exclude weekends is appreciated.
Use the datepart function with the dw part to exclude Saturday and Sunday.
SYNTAX: DATEPART ( datepart , date )
in this case datepart = dw or weekday,
and date is the date field in your query.