COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: et21 on 22 Aug 2022 10:49:14 PM

Title: Count Distinct
Post by: et21 on 22 Aug 2022 10:49:14 PM
Hi All I got a question on Count Distinct, below is what I type in the query

if ([Presentation].[Projects].[Scope Health]= 'Not Stated')
then (1)
else if ([Presentation].[Projects].[Benefits Health] = 'Not Stated')
then (1)
else if ([Presentation].[Projects].[Schedule Health]= 'Not Stated')
then (1)
else if ([Presentation].[Projects].[Resource Health]= 'Not Stated')
then (1)
else (0)

I want it to count if each of the queries contains Not Stated but somehow its just show 1 instead of counting how many are not stated
Title: Re: Count Distinct
Post by: bus_pass_man on 23 Aug 2022 05:09:50 AM
Try re-writing that expression using the case function.


Title: Re: Count Distinct
Post by: et21 on 23 Aug 2022 03:34:44 PM
I did tried to re-write it with case but soemhow its still not working
Title: Re: Count Distinct
Post by: cognostechie on 23 Aug 2022 04:04:57 PM
If the Data Item is marked as a character then it will show  1 because characters are not summed up. Check the properties of the Data Item , what's the Regular Aggregate property set to?

The statement can also be better:

Case
  When (
             [Presentation].[Projects].[Scope Health]= 'Not Stated'
                                    OR
             [Presentation].[Projects].[Benefits Health]= 'Not Stated'
                                    OR
             [Presentation].[Projects].[Schedule Health]= 'Not Stated'
                                    OR
             [Presentation].[Projects].[Resource Health]= 'Not Stated'
            )
    Then (1)
    Else (0)
End
Title: Re: Count Distinct
Post by: et21 on 23 Aug 2022 04:19:18 PM
I did tried to set my Aggregate to total first to see if its sum up or not but somehow its still the same and then changed to count and still not working.
Title: Re: Count Distinct
Post by: cognostechie on 23 Aug 2022 04:33:09 PM
Check the actual data , how many rows does it show?
Title: Re: Count Distinct
Post by: et21 on 23 Aug 2022 05:22:27 PM
the actual data is show as normal but its just not count how many that are not stated, its just show 1 or 0 thats it
Title: Re: Count Distinct
Post by: cognostechie on 23 Aug 2022 05:56:25 PM
I don't know how to help you, makes no sense.
Title: Re: Count Distinct
Post by: cognostechie on 23 Aug 2022 06:01:15 PM
Are you seeing 1 and 0 in the rows or in the total?
Title: Re: Count Distinct
Post by: et21 on 23 Aug 2022 06:04:49 PM
in total
Title: Re: Count Distinct
Post by: cognostechie on 23 Aug 2022 06:07:31 PM
So you said earlier that it shows 1 or 0? What does that mean? It should show only one count so how come it shows both?
Title: Re: Count Distinct
Post by: et21 on 23 Aug 2022 06:16:52 PM
my mistake its either show 1 or 0 but not the total
Title: Re: Count Distinct
Post by: cognostechie on 23 Aug 2022 06:43:08 PM
Check the data and see if the total should be more than 1.

If this is a Data Item in the report then the Regular Aggregate property should be set to Sum and if this is a Query Item in Framework Manager then the usage property should be set to Fact and Regular Aggregate property set to Sum/Total.

Beyond this, I don't know what is happening in your report.

Title: Re: Count Distinct
Post by: bus_pass_man on 24 Aug 2022 06:51:48 AM
What do you mean by
Quoteits either show 1 or 0 but not the total
?   

I'm assuming that you have the calculation in a list report, possibly with stuff from Projects.  For each row where the expression is true you see a 1 and for each you see a 0.  Is that a correct understanding?  What is the value of the summary? Have added a summary?

Check the usage property.   




I'm assuming this is a calculation you are creating in reporting. It might be a good idea to create this sort of calculation as a query item in the projects query subject in your FM model.  Among other things, you would not need to recreate the calculation in other reports and by being defined in one place, the expression would be consistent and inadvertent errors could be lessened.