If you are unable to create a new account, please email support@bspsoftware.com

 

Define measure with "Average" and "Maximum" in Framework Manager

Started by CognosUser222, 28 Oct 2020 04:18:24 AM

Previous topic - Next topic

CognosUser222

Dear Cognos Community,
I have the following problem in Cognos Framework Manager:

I have a table which (simplified) consists of four columns: PERSON_ID, PROJECT_ID, MONTH and NUMBER_OF_DAYS. The rules are as follows:
.)The combination of PERSON_ID, PROJECT_ID and MONTH is the primary key of the table. For each combination of PERSON_ID, PROJECT_ID, there may be several months. If so, NUMBER_OF_DAYS will be NULL in all months except for one (which is the last one with an entry).
.) Given a PERSON_ID, there may be more than one row with NUMBER_OF_DAYS IS NOT NULL. If so, they all have the same MONTH, the same NUMBER_OF_DAYS and different PROJECT_ID.

I want to define a measure "Average" in Cognos Framework Manager that calculates the average NUMBER_OF_DAYS for a time period. NULL values should be ignored and if for one PERSON_ID there is more than one NUMBER_OF_DAYS which is not NULL, than I want only one of them to count for the average (if there is more than one, they are all equal by the rule 2).

Example for the table:
PERSON_ID   PROJECT_ID    MONTH    NUMBER_OF_DAYS
1                    1                  201901     30
2                    1                  201901    NULL
2                    1                  201902     60
3                    1                  201901     NULL
3                    1                  201902     NULL
3                    1                  201903     90
4                    1                  201901     NULL
4                    2                  201901     NULL
4                    1                  201902     50
4                    2                  201902     50

I would like to have the following results for my measure "Average":
201901 : avg(30)=30 (there is only one non-NULL entry for 201901 which is 30).
201902: avg(60,50)=55. (For person 1 and 3, there is no non-NULL entry for 201902. For person 2, it is 60, for person 4, there are two entries and I want to take only one of them).
201903: avg(90)=90.
first quarter 2019: avg(30,60,50,90)=115/2.

So, I want to define a measure in Cognos Framework Manager that does the job. I defined a measure with aggregation type "Average" and with definition

maximum([table_name].[NUMBER_OF_DAYS] for [table_name].[PERSON_ID])

The idea behind the maximum is that both entries for person 4 should get identified and not count twice in the average.
If I create a report with column "Jan. 2019" and row "Average", I get the correct value back (30).
However, if the report has two columns "Jan. 2019" and "Feb. 2019" and row "Average", the number of "Jan. 2019" is no longer correct: It displays avg(30,60,50) instead of avg(30) (I confirmed this conjecture by looking into the SQL).

Report:
             Jan. 2019      Feb. 2019
Average    140/3            55 

So MAXIMUM does not work as I expect. I would like that for "Jan. 2019", Cognos first filters the table on entries of Jan. 2019 and then calculates the maximum and displays the average. But Cognos seems to filter the table on entries of Jan. and Feb. 2019, calculates for each ID the maximum, than filters on Jan. 2019 and then calculates the average.
Do you have ideas on how to achieve this? I tried to replace "maximum" by "running-maximum", but then on a higher level (average of 2019) I obtain numbers which are not the ones I expect.

I am grateful for any inputs and happy to clarify further.

Best,
CognosUser222