How to create a chart Report using Query calculation and displaying date dynamically more than 12 months - cognos-10

I need to create a Chart Report where I need to display the data rolling 12 months and more than 12 months.For example, my Cognos Report is displaying data from Dec2018 to Dec 2019 but post 2019 it should reflect date from Dec 2019 to Dec 2020.
Also, there is a summary sheet below which has values against KPI's and applying some calculations on those value, I need to show in Report.Like, there is a value in KPI (98765) for Dec 2018 and I need to reflect (98765/1000) above.A sample Report is provided below.

Try this Filter
[Date] >= _add_years(_add_days(current_date, -1), -1)
Then for the measures
Definition for the data item rolling 12
IF([Date] <= current_date)Then([Measure])Else(0)
Definition for the data item post
IF([Date] < current_date)Then([Measure])Else(0)

Related

Dax formula - calculate 6 rolling month back average

I have a table named [Tasks] which is linked to a date table named [Dimdate]. They are linked with the date of reference of a tasks [DC_date].
The objective is to have a measure that can calculate the average on in interval of 6 month before the specific date.
For example: if I have a date in 2020 August, the formula will calculate the average from March 2020 to 2020 August.
Here is actually the Dax formula that I have integrated on visual studio but still doesn’t work :
CALCULATE(CALCULATE( [average] ;FILTER(
[TASKS];
DATESINPERIOD(Dimdate[Date];MAX(Dimdate[Date]);-6;Month)));
CROSSFILTER(TASKS[Dc_Date];Dimdate[Date];None)) ```
The relationship on TASKS[Dc_Date] should not be removed, otherwise the Time Intelligence function would not work. Unless there are some other existing filters to be removed, this code should be enough
CALCULATE(
[average];
DATESINPERIOD(
Dimdate[Date];
MAX( Dimdate[Date] );
-6;
MONTH
)
)

How to do "Today Minus Date Field" in Google Data Studio?

I have column long_term_remaining_days, and I want to create a Date field which
will be calculate TODAY - long_term_remaining_days and in this way will display a Date, for example 1 Jun 2020.
I tried to do as in Excel and used the formula below, but it doesn't work:
TODAY() - long_term_remaining_days
One way it can be achieved is by using the new PARSE_DATE, UNIX_DATE and CURRENT_DATE functions (introduced in the 17 Sep 2020 update to Dates and Times).
1) Calculated Date
Copy-paste the Calculated Field below which converts CURRENT_DATE to UNIX_DATE (the number of days since epoch, 01 Jan 1970) and subtracts long_term_remaining_days (where long_term_remaining_days represents the respective Number field), after which it's converted to a UNIX_TIMESTAMP by multiplying with 86,400 (seconds in a day) before then being recognised as a Google Data Studio date using the PARSE_DATE function:
PARSE_DATE(
"%s",
CAST(((UNIX_DATE(CURRENT_DATE())-long_term_remaining_days)*86400)AS TEXT))
Google Data Studio Report and a GIF to elaborate:

Change App Maker table based on date

I have a data model with a field for each month of the year, extending for a few years. I also have a table that displays the data in this model.
I am interested in updating the fields/columns displayed in the table widget based on the current date. I only need the table to display current and the upcoming 12 months not previous ones. For example, it if it March 6, 2018, I would want to have columns in the table for each month between March 2018 and February 2019. On April 1, however, the table should update to drop the March 2018 column and add the March 2019 column.
Is this possible or easy to do in App Maker? If so, what are some tips or relevant resources to look for in the documentation?
If I understand the question correctly then model fields are
Year
January
February
...
December
and you want to display/edit values for them as following:
+-----+--------+--------+-----+---------+
| CM | CM + 1 | CM + 2 | ... | CM + 10 |
+-----+--------+--------+-----+---------+
| V | V + 1 | V + 2 | ... | V + 10 |
+-----+--------+--------+-----+---------+
Where CM is current month, CM + 1 is next month, V value for current month V + 1 is value for the next month, etc...
The most straight forward and easy way to render such UI will be rendering two tables for two records (one for current year and one for next year) and glue them together by playing with CSS styles.
More elegant solution will be dynamic table rendering. This technique is described in answer on this question: Accessing data in Google Drive tables with Google App maker (option #4). Basically you can add two grids to a page, one to render months' names and another to render values for months. You can bind those grids to Calc Model(s) or Custom Properties.

SQLite: Select and count cases where part of the string (year) is lowar than...?

I did already search in past answers for nearly two days but found no solution. I have a table with a column 'projects', column 'country' and a column 'timeframe'. I want to count the number of projects, grouped by country, which did start before 2017. The data looks like
ProjectID CountryID Time
5 3 Enero/2011 - Diciembre/2020
6 3 June 2017 - December 2020
7 3 June 2017 - December 2030
8 5 NULL
9 11 July 2017 - December 2020
10 11 7/2017 - 12/2020
11 5 2017 June - 2020 January
The problem is the format of the Time, but as it is a large dataset I cannot change the format manually. I tried my best to do something like
SELECT *, COUNT (*)
WHERE (Time LIKE '%XX% - %' AND XX < 2018);
but I cannot find the right way to include the parameter XX in the query. Is there any way to get this done without re-writing all data manually?
Thanks a lot!
Thanks Tripehound - substrings did help! For the Start year
SELECT ID, substr(TimeFrame, instr((TimeFrame),'20'),4) AS ProjectStart
, Count(*) AS NumberProjects
FROM Timeframe
WHERE ProjectStart>"2017";
did do the job; for the end year it was
SELECT substr(TimeFrame, instr(TimeFrame,'-')-1+instr(substr(TimeFrame, instr(TimeFrame,'-')), '20'), 4) AS ProjectEnd,
Count(*) AS ProjectsNumber
FROM Timeframe
WHERE ProjectEnd<"2030";
Done!

Oracle Sql get only month and year in date datatype

I want to store only the month and the year in oracle data type.
I have a date like '01-FEB-2010' stored in a column called time_period.
To get only the month and year i wrote a query like
select to_char(time_period,'MON-YYYY') from fact_table;
I go the result as 'FEB-2010' which is fine but the only problem is that it is in varchar datatype.
So I did like
select to_date(to_char(time_period,'MON-YYYY'),'MON-YYYY') from fact_table
and I get 01-FEB-2010. Is it not possible to store only FEB-2010 in the date datatype
Easiest solution is to create the column using the correct data type: DATE
For example:
Create table:
create table test_date (mydate date);
Insert row:
insert into test_date values (to_date('01-01-2011','dd-mm-yyyy'));
To get the month and year, do as follows:
select to_char(mydate, 'MM-YYYY') from test_date;
Your result will be as follows: 01-2011
Another cool function to use is "EXTRACT"
select extract(year from mydate) from test_date;
This will return: 2011
"FEB-2010" is not a Date, so it would not make a lot of sense to store it in a date column.
You can always extract the string part you need , in your case "MON-YYYY" using the TO_CHAR logic you showed above.
If this is for a DIMENSION table in a Data warehouse environment and you want to include these as separate columns in the Dimension table (as Data attributes), you will need to store the month and Year in two different columns, with appropriate Datatypes...
Example..
Month varchar2(3) --Month code in Alpha..
Year NUMBER -- Year in number
or
Month number(2) --Month Number in Year.
Year NUMBER -- Year in number
SELECT to_char(to_date(month,'yyyy-mm'),'Mon yyyy'), nos
FROM (SELECT to_char(credit_date,'yyyy-mm') MONTH,count(*) nos
FROM HCN
WHERE TRUNC(CREDIT_dATE) BEtween '01-jul-2014' AND '30-JUN-2015'
AND CATEGORYCODECFR=22
--AND CREDIT_NOTE_NO IS NOT NULL
AND CANCELDATE IS NULL
GROUP BY to_char(credit_date,'yyyy-mm')
ORDER BY to_char(credit_date,'yyyy-mm') ) mm
Output:
Jul 2014 49
Aug 2014 35
Sep 2014 57
Oct 2014 50
Nov 2014 45
Dec 2014 88
Jan 2015 131
Feb 2015 112
Mar 2015 76
Apr 2015 45
May 2015 49
Jun 2015 40
The recommended solution for this is to have a field / columns defined as DATE or DATETIME datatype.
This is have a proper date formatted value, and to extract just Month-Year from date will be easy, and there are below two ways.
SELECT TO_CHAR(CREATE_DATE,'MON YYYY') FROM DUAL;
This will return the date as "JAN 2022". Also we could change the forma if required.
Could also use "EXTRACT" keyword, but the issue is we have to use it twice to get above format, as EXTRACT will return one value at a time. So first retrieve MONTH and then YEAR (or vice versa).

Resources