Hi I'm trying to calculate the number of days between a date field in my current access table and todays date. Here is what I have:
DAYS ON REPORT: DateDiff("d",[REPORTDATE],[DATE()])
The problem I am having is when I run the query I get a pop up box asking for "Date()"
I am trying to avoid adding a column for "today" and then doing the days between that column and the reportdate column if possible.
REPORTDATE is a column already existing in my table.
DAYS ON REPORT is the field/column I am creating.
When not enclosed in square brackets, Date() is a function call that returns the current system date. Putting square brackets around it turns it into a field name. Since there is no field with that name, the query treats it as a parameter and prompts for its value.
Solution: Get rid of the square brackets.
Related
I have a table with a column called that contains text. Most of the values are years. However, some have the value "present" to represent groups that are still currently active. I want to convert those values to today's year, and convert the column type to date (specifically year type). I want to avoid creating a new column if possible.
Please see below for the DAX language that worked.
= Table.ReplaceValue(#"Extracted Year2",null,DateTime.LocalNow() ,Replacer.ReplaceValue,{"Disbanded"})
Before I start, I want to say sorry my question might be little silly since I'm a newbie for CR.
I put a datediff formula in Crystal Report ver 14.0.12,
and it returns incorrect result for some special cases.
The formula is like below;
DATEDIFF('M',{START_DATE},{END_DATE})
If the start date is 2018-05-01 and the end date is 2020-04-30, the result should be like '24',
but it returns '23'.
It seems if the date range is in the first or final day, it has above error.
In addition, I have another issue with other formula.
I put below formula in order to get 'next date' of certain date field,
DATE(YEAR({date_field}),MONTH({date_field}),DAY({date_field}+1))
and it has an issue when the date field is 'end date' of certain month.
For example, if the date field is 2020-03-31, expected result is 2020-04-01,
but my formula returns like '2020-03-01'.
Please let me know what should I do in order to get correct result.
Thanks a lot:)
In regards to your DateDiff() function.
Did you possibly make a typo when asking your question? The first argument for the function is the intervalType and is a String expression, therefore it should be contained within double quotes; you have single quotes in your question. Using single quotes should throw a syntax error. Also, the intervalType for Month should be expressed as a lowercase "m".
As for your issue with adding 1 day to a date, I would recommend using the DateAdd(intervalType, nIntervals, startDateTime) function to complete this task. Try this formula instead:
DateAdd("d", 1, {date_field})
However, be aware that this function will return a DateTime value, so if you want to remove the timestamp from the date that is returned, you will want to cast the entire function as a Date datatype using the Date() function as follows:
Date(DateAdd("d", 1, {date_field}))
Single quote is fine. Source of the problem is that adding 1 to 31 is 32 (which gets wrapped back to 1 due to date logic).
Suggestion above to use DateAdd() is the correct solution.
I'm attempting to make the parameters for a Crystal Report more user-friendly for a client, who has requested that they be able to have the default values for a Start and End date parameter be the first and last day of the previous month.
I know how to use either a formula in CR or a stored procedure to produce these values, but I want to know if a variable can be used in the 'Default Value' setting for a parameter, or if it only allows for static entries. Does anyone know? Right now the user can set the date parameters to null and the stored procedure generates the data for the previous month on its own, but I thought it'd be nice if the date parameters actually displayed the dates that were being used as defaults. Thanks in advance!
You can do it, Try below process:
Create a parameter ?date with String datatype and take static and write two default strings as below:
First day of previous month
Last day of Previous month
Now go to record selection formula and write below code:
if ({?date}="First day of previous month") then
table.date=DateSerial(year(currentdate),Month(Currentdate)-1,1)
else if ({?date}="Last day of previous month")
then
table.date=Cdate(DateAdd("d",-1,DateSerial(year(currentdate),Month(Currentdate),1)))
I've been looking into making a date selector so instead of filtering by Month, Week by adding filters then displaying the quick filters to correspond. I want to be able to dynamically change the date so I can choose between Quarter, Month and Week in a single drop down.
I have made the selector part no problem it shows but when I come to my calculated field, it's not behaving how I would like.
Here is my calculated field:
CASE [Parameters].[Date Select]
WHEN 'Quarter' THEN QUARTER([Date])
WHEN 'Month' THEN MONTH([Date])
WHEN 'Week' THEN WEEK([Date])
END
This gives 2 errors...
Unknown Function QUARTER called
Unknown Function WEEK called
I am puzzled because the month one is fine.
Normally in tableau to get the month/quarter/week, I click on the Date dimension and select Month or week and it filters and displays like so: MONTH(Date).
Can anyone tell me where I'm going wrong and how I can pull the week and quarter from date in the calculated field so my selector will work.
Thanks.
There are no QUARTER and WEEK functions in Tableau, as you can see in the image below.
What you should be using to get these values are:
DATEPART('quarter',[Date])
DATEPART('week',[Date])
For filtering the date using your parameter as filter, I'll assume that you want to filter the current quarter, month or week. In this case you'll need to setup your paramaters like this:
Then you'll create a Calculated Field with the following formula:
DATEPART([Date Selector],[Date]) = DATEPART([Date Selector],TODAY())
This should give you a True/False dimension which you will use as filter for the value True. After that you should have a working parameter filtering your data accordingly to the value set.
I need to filter my query with different time intervals like that:
...
where
date >= '2011-07-01' and date <='2011-09-30'
and date >='2012-07-01' and date >='2012-09-30'
I suppose such code is not good, because these dates conflicts with each other. But how to filter only these two intervals, skipping everything else? Is it even possible? Because if I query like this, I don't get any results.I tried to use BETWEEN, but it does same thing.
I bypassed this by extracting quarters from years and calculating only third quarter. But then other quarters sum is showed as zero and I can't ignore these rows that have sum column with zero value. I tried to filter where price > 0 (column where sum goes), but it says that column do not exist. So I put it whole FROM under '('')' brackets to make it calculate sum before where clause, but it still does give me error that such column do not exist.
Also if you need to see query I have now, I can post it, just tell me if it is needed.
I want to do this, because I need to compare third quarter of two different years (maybe I should use another approach).
You're not going to get any results because you can't have a date that's both within 7/1/2011 through 9/30/11 and after 7/1/2012 and after 9/30/12.
You can have a date that is either between 7/1/20122 and 9/30/2011 or between 7/1/2012 and 9/30/2012.
SELECT col1 FROM table1
WHERE date BETWEEN '7/1/2011' AND '9/30/2011' OR date BETWEEN '7/1/2012' AND '9/30/2012';