Cognos report studio filter from Feb data to last closed month - cognos

Cognos report studio filter from Feb data to last closed month.
I need to build a report that should show data from Feb to last closed month.
If I run the report in March, it should show the data only for Feb.
If I run the report in Dec, it should show the data from Feb to Nov.
If I run the report in Jan, it should show the data from Last Year Feb to last year Dec.
If I run the report in Feb, it should show the data from Last Year Feb to current year Jan.
Is anyone can help?
#Cognos # CognosBI #CognosDeveloper.

Create a filter expression of [Itemtobefiltered] between [StartDate] and [EndDate]
The [StartDate] query calculation should have an expression of:
if (extract(month,current_date)<=2)
then
(_first_of_month(_add_years(current_date,-1)))
else
(cast(cast(extract(year,current_date),varchar(4))+'-02-01',date))
The [EndDate] query calculation should have an expression of:
_last_of_month(current_date)

Related

IIF Date falls BETWEEN two dates using SSRS

I am using SSRS 2016 and trying to compare a field to check if the Month falls between two parameters, as following:
=IIF(Format(Fields!FromDate.Value, "MMM") BETWEEN (Format(Parameters!FromDate.Value, "MMM") && (Format(Parameters!UnilDate.Value, "MMM") ), Fields!Days.Value, "0")
I have manually setup some fields in the dataset to display Jan to Dec. The aim is to show each result in its relevant month when you select the parameters: FromDate and UntilDate
What am I missing here?
I just replicated your scenario on my local report project.
Below is the expression you should try.
Note: What happens when your From date is June 2020 but To date is Aug 2019.
This will work because we are only checking months in between but not Years and so on.
But this should be a starting point for you to update your logic.
=IIf(Format(Fields!FromDate.Value, "MM")>= Format(Parameters!FromDate.Value, "MM")
and Format(Fields!FromDate.Value, "MM")<=Format(Parameters!UnilDate.Value, "MM"),
Fields!Days.Value,"0")
Edit for only current Year
=IIf(Year(Fields!FromDate.Value)>=Year(Parameters!FromDate.Value) and Year(Fields!FromDate.Value)<=Year(Parameters!UnilDate.Value) and Month(Fields!FromDate.Value)>=Month(Parameters!FromDate.Value) and Month(Fields!FromDate.Value)<=Month(Parameters!UnilDate.Value) , Fields!FromDate.Value,"0")

Filter dates by month in pivot table that doesn't start with the 1st of every month

Does anyone know how to filter dates by specific dates by month such as Jan 15 to February 15, Feb 15-March 15....etc on pivot table in excel?
My data is January 15 2017 to January 15 2018, so I like to filter it by specific dates but so far it's only letting me do the number of days which is not accurate since feb has only 28 days. thank you!

How to count running months of a specific year?

I'm currently struggling with calculating the running months depending on the year. I have the following table:
Received Month Received Year
Feb 2018
Feb 2018
Mar 2018
... ...
Nov 2018
Nov 2018
Dec 2018
Dec 2018
Jan 2019
Jan 2019
Feb 2019
I was using this formula to count the # of unique months (running months in 1 single cell [C1]);
=SUMPRODUCT(1/(COUNTIF(KAIZEN_Table[Received Month],KAIZEN_Table[Received Month])))
This was working great in 2018, it gave me 11 (Feb - Dec).
I have to add a filter that also checks if the year is 2019. I can't remove 2018 in the table because the operators are still using the 2018 lines. The filter is just here to set a KPI for 2019.
For some reason I can't figure out how to add the year. I tried;
=SUMPRODUCT(1/(COUNTIFS(KAIZEN_Table[Received Month],KAIZEN_Table[Received Month],KAIZEN_Table[Received Year], "2019")))
This is just giving me a 0.
Any suggestions on this? VBA code is also fine.
Edit: After extensive googling I found a working formula, for whoever might be interested in this.
=SUM(IF(FREQUENCY(IF(tbl[Year]=2019,MATCH(tbl[Month],tbl[Month],0)),ROW(tbl[Month])-ROW($L$5)+1),1))
L5 = First row of tbl[Month]
I have my data in A1:B14, the formula I've used is an array one
=SUM(1/(COUNTIFS($A$1:$A$14,$A$1:$A$14,$B$1:$B$14,$B$1:$B$14)))
however,
=SUMPRODUCT(1/(COUNTIFS($A$1:$A$14,$A$1:$A$14,$B$1:$B$14,$B$1:$B$14)))
would suffice
To do a particular year, you could do something like this
=SUM(($B$1:$B$14=2019)*(1/COUNTIFS($A$1:$A$14,$A$1:$A$14,$B$1:$B$14,B1:B14)))
Another approach is to use a Pivot Table.
On the Create Pivot Table dialog, select to Add this data to the Data Model
If you do this, you will note that one of the options in the Value Field Settings will be Distinct Count
Drag Received Year to the Rows Column; Received Month to the Values column, and select Distinct Count for the Value Field Setting

Pivot table Sort month for different years

Hi I am pivoting data grouped by months. The months are spanned across 2 years with the start date being in july 2018 going back to august 2017. However when i try to sort the data, it always start with Jan 2018 first and goes alphabetically. How can i make it do chronologically. Also is there a way to change the date to say m/yy? I keepy trying field settings then number format and its not working
Date
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
<8/1/2017
An option could be to group years as well. Right-click a cell with one of the months > group > select Years and months. This will put the months in chronological order.

How to exclude the February 29 - Leap Year in a Date column using Cognos 10 Report Studio?

How do I exclude the February 29 - Leap Year in a Date column in Cognos 10 Report Studio?
This is the column that I'm using for my date prompt
Below is the prompt that I applied on the date column
Depicted below is the details and properties of the date prompt that I will use to filter my report using the date prompt.
So all attributes and measures in the report are filtered using the start date and end date of the expiration date column I used on the report.
How do I avoid the February 29th to add up in my calculated columns (measures)? I want to get all calculation from January 1 to Dec 31 without february 29 that happens every four years? The February 29 data may or may not include a large amount but it has a ripple effect at the year end calculation. That's why I want to exclude Feb 29 included in the computation.
Here's a filter expression that will exclude "leap days":
not (extract(month,[Policy Expiration Date]) = 2 and extract(day,[Policy Expiration Date]) = 29)
Kindly try this.
([Policy Expiration Date] between ?Expiration Start Date? and ?Expiration End Date?)
AND
to_char([Policy Expiration Date],'mmdd') <> '0229'

Resources