FY vs last FY Cognos 11 - cognos

I am looking to generate report in Cognos 11 for attended appointments for this FY vs last FY for the same time frame. For example of I am running report on 1st June 2021, I should get data for sum of appointments of April and May 2021 and sum of appointments of April and May 2020.
Please let me know how can I set the date filter.
Thanks

You didn't provide any context. There are many ways to do this. Just providing a filter expression won't work because I don't know what the rest of your report looks like.
Describing such a general solution for Cognos in plain text is not simple. I'll also assume that, since you are using Cognos, the database structure is a star schema containing a time dimension with columns named [FiscalYear] and [FiscalMonthNumber] that are integers. Also, that your fiscal year runs from January 1 to December 31.
Using Cognos functions:
[FiscalYear] * 100 + [FiscalMonthNumber]
between
_year(_add_months(current_date, -2)) * 100 +
_month(_add_months(current_date, -2))
and
_year(_add_months(current_date, -1)) * 100 +
_month(_add_months(current_date, -1))
or
[FiscalYear] * 100 + [FiscalMonthNumber] + 100
between
_year(_add_months(current_date, -2)) * 100 +
_month(_add_months(current_date, -2))
and
_year(_add_months(current_date, -1)) * 100 +
_month(_add_months(current_date, -1))
Using Cognos macros:
[FiscalYear] * 100 + [FiscalMonthNumber]
between
#timestampMask (_add_months($current_timestamp, -2), 'yyyymm')#
and
#timestampMask (_add_months($current_timestamp, -1), 'yyyymm')#
or
[FiscalYear] * 100 + [FiscalMonthNumber] + 100
between
#timestampMask (_add_months($current_timestamp, -2), 'yyyymm')#
and
#timestampMask (_add_months($current_timestamp, -1), 'yyyymm')#
The advantage of using the Cognos macro is that the value is computed once before sending to the database server, rather than the database server computing it for every row.

Assumption that you have a data item like invoice date, etc, for the example this will be [Date] but you could change the filter to what makes sense based on your data items
The filter could use a date prompt with a parm i.e. PrmDate or use Current_date
see explanation below
Filter should look like:
([Date] between [CurrentStart] and [CurrentEnd])
OR
([Date] between [PriorStart] and [PriorEnd])
Create some data items to make this a little easier
Offset, note: the offset allows you to change your starting month/period
This would be for January
extract(month, current_date) -1
This would be for April
extract(month, current_date) -4
CurrentStart
_first_of_month (_add_months(current_date, -[Offset]))
CurrentEnd, note: if you don't want a prompt, just swap ?PrmDate? with Current_date
_add_months(?PrmDate?,-1)
PriorStart
_add_years([CurrentStart], -1)
PriorEnd
_add_years([CurrentEnd],-1)

Related

Trying to show a full years amount based on a smaller fraction of the year's total

this is my first post.
Right now, I have a limited set of data ranging from the beginning of this financial year until now. I'm trying to show what a full year's worth of that data would look like.
For example, if the number is at 10, and the data range is from 1/07/2021 - 30/12/2021 (half the year), then the end output should be 20. Or for example, turn a 12 with 3/4 of the year date range to 16 for a full years' worth.
However, my current formula would end up with 15 (10 + "half") rather than (10 + 10)
Right now this is what I have, but I know there's something off on my logic, as the output is smaller than it should be:
D1+((364-(F1-E1))/365)*D1
where E1 is the start date and F1 is the end date, and d1 is the number for that date range
Thanks in advance
endDate - startDate will give you the number of days the data covers.
(endDate - startDate) / 365 will give you what fraction of a year the sample represents.
Let’s say this works out to be 30%, or 0.30.
annualValue * 0.30 = periodValue and therefore we know that periodValue / 0.30 = annualValue.
So there it is, the cell you want the Annual Value in should be:
= periodValue / ( ( endDate - startDate) / 365 )
I will leave it to you to replace each of the three named values in my example to be the correct cell references. I suspect that’s probably:
=D1/((F1-E1)/365) which is the same as (D1*365)/(F1-E1).
The easy way to remember this is that it’s just cross-multiplication.
periodValue / days is proportionate to annualValue / 365. Thus periodValue / days = annualValue / 365. Cross-multiply and you get periodValue * 365 = annualValue * days. Divide both sides by days and you get `annualValue = (periodValue * 365)/days.

How to add plus 1 day to a timestamp in Cassandra SQL?

I am trying to add 1 day to a timestamp field.
Below is what I have tried but not working:
select studentid, (course_date + 1) as nextday from students where studentid=123;
select studentid,(course_date/DAY+1DAY) as nextday from students where studentid=123;
Kindly help.
Yes, you can specify a time component along with the date arithmetic. In this case, changing 1 to 1d (one day) solves this:
> SELECT studentid,course_date + 1d as nextday FROM students WHERE studentid=1;
studentid | nextday
-----------+---------------------------------
1 | 2022-01-04 06:00:00.000000+0000
(1 rows)
For more information, I recently wrote a blog post on the use of Arithmetic Operators in Apache Cassandra 4.0 as well as a short video on this topic! Below is a more comprehensive list of the valid time duration codes:

How to get the Week of the month (1:6)

We can find different approaches to determining the week of the month, and even though there are many pages on 1:4 and/or 1:5, there is very few around 1:6 approach.
So to give you a bit of the context, I am working with a pivot table in Excel which gets its values from a Power Query source.
In Power Query, there is a function Date.WeekOfMonth which takes in the date and returns a number between 1 and 6.
In this definition, weeks start from Sunday and ends on Saturday.
So, for example, the first two days of October 2021 -i.e. Fri & Sat- fall in the 1st week of Oct, while the 3rd day of Oct 2021 starts the second week, and then the last day of October 2021,i.e. Oct 31, is the only day in the 6th week.
I had an automation task on hand in which I needed to pull data from the Power Query-generated pivot, so I had to implement a piece of code in VBA which calcs weeks the same.
Unfortunately, I couldn't find any prepared snippet, so after implementing I though it might worth sharing.
(Any comments and suggestions appreciated)
The DatePart function is perfect for this. Using DatePart with the interval set to "weeks" you can find the week of a given date. Then you subtract the number of weeks before the first day of that month (which sets the first day to week = 1).
Function WeekNumOfDate(D As Date) As Integer
WeekNumOfDate = DatePart("ww", D) - DatePart("ww", DateSerial(Year(D), Month(D), 1)) + 1
End Function
Here is a second version of the function that has the ability to set the FirstDayOfWeek argument:
Function WeekNumOfDate(D As Date, Optional FirstDayOfWeek As VbDayOfWeek = vbSunday) As Integer
WeekNumOfDate = DatePart("ww", D, FirstDayOfWeek) - DatePart("ww", DateSerial(Year(D), Month(D), 1), FirstDayOfWeek) + 1
End Function
As an example for using FirstDayOfWeek: With FirstDayOfWeek set to vbThursday, the date "Nov 5th, 2021" will return as Week 2, whereas it would by default be counted as Week 1. November 1st to 3rd of 2021 will be week 1, and then 4th to 10th will be week 2.
Its implementation in VBA is:
Function WeekOfMonth(My_Date As Date)
If Day(My_Date) > Day(My_Date - 1) And Weekday(My_Date) > Weekday(My_Date - 1) Then
WeekOfMonth = WeekOfMonth(My_Date - 1)
ElseIf Day(My_Date) > Day(My_Date - 1) And Weekday(My_Date) < Weekday(My_Date - 1) Then
WeekOfMonth = WeekOfMonth(My_Date - 1) + 1
Else
WeekOfMonth = 1
End If
End Function
Note that even though the above function is recursive, its time and space complexity is an expression of order N, which here cannot exceed 31.

NetSuite Saved Search Formula for This Week

I am trying to create a saved search that shows total orders today, yesterday, this week and this month. I am able to get all but the weekly one using date formulas.
All are Formula(Numberic) fields with summary type Count.
Today: CASE WHEN {trandate} = to_date({today}) THEN {number} END
Yesterday: CASE WHEN {trandate} = to_date(({today} - 1)) THEN {number} END
This Week??
This Month: CASE WHEN {trandate} BETWEEN to_date(TRUNC({today}, 'MONTH'), 'MM/DD/YYYY') AND to_date(LAST_DAY{today}) THEN {number} ELSE 0 END
Any suggestions appreciated!
The way to get this depends on whether you want values for the last 7 days or for this calendar week.
For the last 7 days:
case when {now} - {trandate} < 7 then {number} else 0 end
or for the current week
case when to_char({now}, 'IW') = to_char({trandate}, 'IW') then {number} else 0 end
where 'IW' is for the ISO Standard week numbering. You can also use 'WW' for week numbering where week 1 starts on Jan 1, week 2 on Jan 8 etc.
I'd suggest calculating the day of the week and using that to work back to the start of the week.
I have not tested, but my understanding is that Oracle db functions should work.
to_date({today} - to_char({trandate}, 'D'))
https://livesql.oracle.com/apex/livesql/file/content_GCEY1DN2CN5HZCUQFHVUYQD3G.html

Tableau report count total number of articles based on article's publish and unpublish date, filter by parameter control date range

I am newbie to Tableau reporting and need your help to enlighten me on Tableau.
I am looking for a way to count total number of articles based on article's publish and unpublish date, filter by parameter control date range.
I have provided the sample data and sample report for the challenge I am facing.
Basically every article will have publish and unpublish date, I need to count total number of article for each day, based on the date range user select from parameter control.
E.g. If user choose to show article number from 1st Jun to 5th Jun, report X-axis will only from date from 1st Jun to 5th Jun.
I have tried to use calculated field, but seems only can calculate for a day.
2 challenges I see:-
1) How to loop through date range for parameter control
2) How to aggregate total article each day based on publish data and unpublish date
Sample data:-
[ArticleNo][Publish Date][Unpublish Date]
110 2014-May-01 2014-Jun-03
111 2014-Jun-02 2014-Jun-03
112 2014-Jun-03 2014-Jun-30
Sample report format, bar/line graph:-
Report date range : 2014-Jun-1 to 2014-Jun-5 (Parameter Control)
Number of Article Published
^
4 |
3 | X
2 | X X
1 | X X X X X
---------------------------------------------->
| 1-Jun 2-Jun 3-Jun 4-Jun 5-Jun
Report Date Range
I tried to use the following calculated field, but seems can only calculate for a day:-
My calculated field
IF ([Date From] >= [Publish Date] and [Unpublish Date] <= [Date To]) THEN
DATEDIFF('day',[Date From],[Unpublish Date]) + 1
ELSEIF ([Date From] >= [Publish Date] and [Unpublish Date] >= [Date To]) THEN
DATEDIFF('day',[Date From],[Date To]) + 1
ELSEIF ([Date From] <= [Publish Date] and [Unpublish Date] <= [Date To]) THEN
DATEDIFF('day',[Publish Date],[Unpublish Date]) + 1
ELSEIF ([Date From] <= [Publish Date] and [Unpublish Date] >= [Date To]) THEN
DATEDIFF('day',[Publish Date],[Date To]) + 1
END
Thanks for your help first. Cheers.
One solution is to first reshape your data to make the reporting easier, possibly using a custom SQL data connection or data blending or pre-processing.
The custom SQL approach can use a UNION ALL clause to combine a table with itself; data blending can do similar tricks on the client side by having two similar copies of the connection.
Here is a long but good thread discussing a similar, but not identical, problem set.
http://community.tableausoftware.com/thread/120614
Hope this gets you started - no time to write more detail right now.

Resources