Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Distinct count with both And/OR conditions

Hi,

I have created the statement below, which successfully counts PARTY_ID that meets all four criteria of date range and types of play count. I'm trying to modify this to perform the distinct count that fits in the date range AND any of the three play_counts rather than  all of them.  I tried changing the operator between the play_counts from , to * however this just gives me an error.

Thanks in advance for any help or suggestions

=(COUNT(distinct
{$<
[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"},
[REAL_PLAY_COUNT] = {'1'},
[RELEASED_PLAY_COUNT] = {'1'},
[PLAYABLE_PLAY_COUNT] = {'1'}
>}
[PARTY_ID]
)
)


1 Solution

Accepted Solutions
sunny_talwar

May be this:

=COUNT(distinct {$<[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"}, [REAL_PLAY_COUNT] = {'1'}> + <[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"}, [RELEASED_PLAY_COUNT] = {'1'}>+<[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"}, [PLAYABLE_PLAY_COUNT] = {'1'}>} [PARTY_ID])

View solution in original post

6 Replies
jolivares
Specialist
Specialist

If I understand you, your require is :

=(COUNT(distinct
{$<
[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"}>+
<[REAL_PLAY_COUNT] = {'1'}>+
<[RELEASED_PLAY_COUNT] = {'1'}>+
<[PLAYABLE_PLAY_COUNT] = {'1'}
>}
[PARTY_ID]
)
)

sinanozdemir
Specialist III
Specialist III

It seems like you have extra parenthesis

=(COUNT(distinct
{$<
[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"},
[REAL_PLAY_COUNT] = {'1'},
[RELEASED_PLAY_COUNT] = {'1'},
[PLAYABLE_PLAY_COUNT] = {'1'}
>}
[PARTY_ID]
)
)

just get rid of them so like the below:

=(COUNT distinct
{$<
[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"},
[REAL_PLAY_COUNT] = {'1'},
[RELEASED_PLAY_COUNT] = {'1'},
[PLAYABLE_PLAY_COUNT] = {'1'}
>}
[PARTY_ID]
)

Not applicable
Author

Thanks Juan, this works aside for the date range is also an OR. I'm hoping Im explaining this correctly. Let me try another way:

Current:

Date Range AND Real_Play_Count AND Released_Play_Count AND Playable_Play_Count

Desired:

Date Range AND (Real_Play_Count OR Released_Play_Count OR Playable_Play_Count)

sunny_talwar

May be this:

=COUNT(distinct {$<[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"}, [REAL_PLAY_COUNT] = {'1'}> + <[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"}, [RELEASED_PLAY_COUNT] = {'1'}>+<[COUNT_DATE] = { ">=$(vStartDate)<=$(vEndDate)"}, [PLAYABLE_PLAY_COUNT] = {'1'}>} [PARTY_ID])

maxgro
MVP
MVP

=COUNT(

       {$

            <COUNT_DATE={">=$(vStartDate)<=$(vEndDate)"},REAL_PLAY_COUNT={1}>             +

            <COUNT_DATE={">=$(vStartDate)<=$(vEndDate)"},RELEASED_PLAY_COUNT={1}>    +

            <COUNT_DATE={">=$(vStartDate)<=$(vEndDate)"},PLAYABLE_PLAY_COUNT={1}>

       }

distinct PARTY_ID)

Not applicable
Author

Thanks Maxgro! I marked Sunny's as correct only because he got there first. Both of you were correct and as always I super appreciate everyones help!

Cheers

Grant