How can I calculate the YoY on cognos 11.1? - calculation

Is it possible to know somebody how can I calculate/make the YoY, MoM filter on Cognos 11.1 expression editor ??? Mt file has the following structure. Same logic applies for months at the Date field.

Year over year
Can you build a data item like this? Example uses [Sales] as the metric you want conditioned.
IF ([Work Date] between date(extract(year,[Target Date]) || '-01-01')
and [Target Date]) then ([Sales])Else(0)

Related

Neo4j: How to calculate year difference between particular date and today's date in neo4j 3.x version?

I have nodes with person label where i am storing their date of births too. For e.g.:
Person
{
name: Tim
D.O.B: 01/23/1990
}
Now I need to calculate his age as of current date and time ( i.e. either 27 years or 27 years, 10 months, 18 days ). So, could anyone let me know how could I perform it?
P.S.: I tried the following but seems to be missing something here :
WITH apoc.date.parse('01/23/1990', 'y', 'MM/dd/yyyy') AS startDate,
apoc.date.format(timestamp(),'y','MM/dd/yyyy') as endDate,
apoc.date.parse(endDate,'y','MM/dd/yyyy') as ed
RETURN ed - 4
The units supported by the APOC date format/parse/add/convert functions are: ms,s,m,h,d and their long forms. To work with months, you need to be working with a specific calendar system, and there is no common month unit of time to do conversions or additions, as different months are comprised of different days (then there's the leap days in February).
For years, you're going to have to go with day units and use division by 365.
Here's a query that will get you age in years and days.
WITH apoc.date.parse('01/23/1990', 'd', 'MM/DD/yyyy') as birth, apoc.date.convert(timestamp(), 'ms', 'd') as now
WITH now - birth as daysAlive
RETURN daysAlive / 365 as yearsAlive, daysAlive % 365 as daysExtra
If you want to get into months, it may be better to work with the month/year fields from the MM/DD/yyyy representation and pull some mathematics on those. I'll see about what we can for supporting that in APOC.
Some like
WITH apoc.date.parse('01/23/1990', 'y', 'MM/dd/yyyy') AS startDate
RETURN apoc.date.convert(timestamp() - startDate,"ms","d");
perhaps ?
Hope this helps.
Regards,
Tom

Query does not return end date records

I have a date range search in rails but for somereason the query below does not include dates that are same as end date.
Sale.where("created_at >= ? AND created_at <= ?","Fri, 15 Jul 2016", "Sat, 16 Jul 2016")
anyone care to enlighten me?
I am using date_fields in a form to send date and search within Sales table.
What is the database that you are using? I think that depending on the database provider it cannot determine the > operator.
For date ranges the best would be to use this statement that translates into "sales"."created_at" BETWEEN ? AND ?
Something like this:
Sale.where(created_at: Date.today - 1.day..Date.today)
Modify to use the date range to suit your use case
hope it helps
It seems the reason it did not bring up my records on end date is because i needed to clarify the time as well. So i needed to search records by end of day.
I am using postgres database and here is what worked.
Sale.where("sales.created_at >= ? AND sales.created_at <= ?", date_start.beginning_of_day, date_end.end_of_day)

Comparing datetime and date in a .where() on Rails

I'm working on an event system where admins can select events to feature and add promotional text. As they need to add additional text the featured events are in their own table and reference the event details.
I'm now trying to output featured events for each day in the next week. Simplified example:
day = DateTime.now.to_date
featured_events = #featured_events.where('event.start_datetime = ?', day)
The problem is that start_datetime is in datetime format and day is in date format so it always outputs nothing. Is it possible to compare these two values with .where()?
Thanks!
May be you're looking for this:
#featured_events.where('event.start_datetime > ? and event.start_datetime < ?', DateTime.now, 1.day.from_now.beginning_of_day)
You don't say what database you're using.
In PostgreSQL we'd truncate the datetime inside the DB query so the DBM can do the compare. On MySQL we'd use a function to convert the datetime to a date.

evaluate difference between 2 dates to make a transition possible

Is this possible to evaluate the duration between a specified date on a form of a workflow, and the system date ? that what I want to do, in order to show (if this possible too) a short message if 1 day occurs since the specified date above, forbidding the transition of the status Closed to Reopened...
Thanks a lot,
Christophe
I think the Script Runner has a validator that does something like this but I can't find it. Then you could write a post function with the Script Runner. Otherwise it's back to creating a custom validator, as described in my book Practical JIRA Plugins (O'Reilly)
You can use the ScriptRunner plugin in addition with the following script in the validator section for the Reopened transition:
Date now = new Date()
Date cfDate = new Date(cfValues['YourCustomField'].getTime())
new Date(now.getYear(), now.getMonth(), now.getDate()).compareTo(cfDate) <= 0
Replace YourCustomField with the name of your custom field. This will ensure that the transition will check whether the current date is beyond the date set in the custom field, and blocks it if it is.
First of all, thank you for your answer.
It works to allow transition when dates are similar, but my purpose was modified by my responsible. He would like to allow the transition if dates are similar or if the duration between them is only 1 day or less.
Example :
System date is 09/07/2013 (Paris)
My date (dd/mm/yyyy format) Transition allowed Why
07/07/2013 NO my date is former to system date
08/07/2013 NO my date is former to system date
09/07/2013 YES my date and system date equals
10/07/2013 YES only 1 day occur between 2 dates
11/07/2013 NO 2 days occur between 2 dates
Here is the code I wrote in order to do that, but it does'nt work (maybe a Java syntax error?) :
Date now = new Date()
Date cfDate = new Date(cfValues['Date de clôture réelle de la demande'].getTime())
new Boolean(((now.getTime() - cfDate) / 86400000) <= 1) && (now.getTime() >= cfDate ))
Excuse me for my english. I'm french, and I try to improve my English.
Thanks a lot.

Language to express complex time multi-intervals?

I'm wondering if anyone knows of any declarative language to express absolute date-time multi-intervals. I mean sets which are the union/intersection/complement of time intervals.
Intervals I would like to represent are like:
(
(from the second day of the month to the 10th) intersection (months 1,2,3,10)
)
union
(
(from the second monday of january to the 3rd of july) intersection (not in(mondays, fridays))
)
I'm not looking for a library, but rather to some language specification.
An example of what I'm looking for are the cron expressions you can find here.
It seems somebody has finally devised a dsl just for that: schyntax .
Well, you might not be looking for a library, but the JODA library for Java, when in use, comes close in structure of it's usage to what you have shown. Do look at it.
A dialect of SQL, maybe?
Date from Days
where Month in (Jan, Feb, Mar, Oct)
and Day between 2 and 10
union
Date from Days
where Date between SecondMondayOf(Jan) and July,3
and DayOfWeek not in (Mon, Fri)

Resources