Difference between previous and current month - qliksense

I'm trying to calculate the difference between current month and previous month.
The date field in my DB called C_DATE (dd/MM/YYYY), and I'm using in my sheet a date filter in the format: Year(C_DATE)&'-'& Num( Month(C_DATE),'00'). So when the user choose month (for example 2022-05), he will see the difference in the data between May and April.
I've already tried to calculate by:
count ({<Answer_num={">=6"}, C_DATE={">=$(=(MonthStart(Max(C_DATE))))<=$(=(MonthEnd(Max(C_DATE))))"}>}Answer_num) -
count ({<Answer_num={">=6"}, C_DATE={">=$(=(AddMonths( MonthStart(Max(C_DATE)),-1)))<=$(=(MonthStart(Max(C_DATE)))))"}>}Answer_num)
but i'm getting wrong outcome. is it maybe because of the date filter format? What can I do?
Thank you!

I think this is a matter of getting the date format correct and using the proper set operator. This may work:
=Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))<=$(=Date(MonthEnd(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
-
Count({1<Answer_num={">=6"}, C_DATE={">=$(=Date(AddMonths(MonthStart(Max(C_DATE)),-1), 'DD/MM/YYYY'))<=$(=Date(MonthStart(Max(C_DATE)), 'DD/MM/YYYY'))"}>*$} Answer_num)
This adds the =Date(..., 'DD/MM/YYYY') expression to the set expressions so that the formatting matches the format of the [C_DATE] field. We also add the * set operator so that we get the intersection between the selection ($) and our ">=...<=..." set expression.
I'm sort of guess on the use of the intersection operator, it could be that the union operator (+) is the correct one to use in this case.

Related

How to get last day of previous month in DataStage?

I explored all the functions available in the transformer, but I couldn't find the exact function to get the last day of the previous month in standard format, i.e. dd/mm/yyyy. Please help me in this regard.
The field that needs to appear is in the COL_C field.
enter image description here
inside it I can't put anything that returns me this result
You can use DateOffsetByComponents to substract the current day.
Cut out the day part from your date and substract it with above function.
i.e. 16/12/2022 - 16 = 30/11/2022

Google Sheets - IF Statement - Null date (1/1/2500) workaround

I am working on a large nested IF statement that checks several validation points for each row of my sheet. There are several date validations, including chronological order and certain fields not being future dates. However, our system requires that if we must null any dates for processing, that date becomes 1/1/2500, and no matter what I do I cannot seem to get the formula to ignore this date when accounting for future dates or chronology.
//The date cannot be later than the current date - I want this to ignore 1/1/2500
IF(K1<>1/1/2500,"",IF(AND(K1>TODAY()),"Date A cannot be future date",""))
//The two dates must be in chronological order, also ignoring 1/1/2500
IF(U1<>1/1/2500,"",IF(AND(U1>AA1,AA1),"Date A, Date B should be in chronological order",""))
The above approach does not seem to recognize 1/1/2500, even though I got it to work with other dates.
I also tried going with >12/31/2099 (ignore any date greater than 12/31/2099) but it just ignores every date.
Any help would be appreciated.
It looks as though it is failing because K1 is compared to 12/31/2099.
If you use an expression like this in a formula, it will interpret it as an arithmetic expression 12 divided by 31 divided by 2099, which is a very small number, so the greater than test will always be true.
Try starting the formula with Date to convert a year, month, and day into a date.
If(K1>date(2099,12,31)
and you should get the right answer.
See my previous answer for Excel.

Datediff in Crystal Report

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.

DATE FORMATTING - COGNOS

I am using cognos version 10 and I need my dates to display in this format 'yyyy-mm' but it is showing dates like '2014-04' as '2014-4' so it is reading the dates out of order by producing '2014-11' first because it starts with a one. I need to add a zero to those double digit integers that way the months(specifically) will display in order.
here's an the code I've created in attempt:
_year( start_date ) ||'-'|| _month( start_date )
IF(_month(start_date) > 10)
THEN('0' +_month(start_date))
Short answer: Use yyyy-MM.
Your question lacks a lot of detail, so my response is based on considerable guess-work.
Are you asking about formatting, or do you want to transform the values? Formatting can be done without code. The code for your data item should be start_date.
Is this for a List column body? Where do you enter your format (yyyy-mm)? Are you using the Data format property?
In the Data format dialog, if you can't find another setting that will do what you want, you can enter a pattern into the Pattern property. If you look at the tips at the bottom of the Data format dialog, you'll notice that using yyyy-mm would give you a four digit year, a hyphen, and a two-digit minute. Perhaps you should try yyyy-MM. It works for me.
As for sorting: Even if you used yyyy-M for the pattern, 2014-04-22 (displayed as 2014-4), should sort before 2014-11-01 (displayed as 2014-11). The only reason the sort would be wrong is if it is using some other data besides the dates.

Tableau Using Parameters for a Date Selector

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.