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: 
Meg00
Contributor III
Contributor III

avg of distinct values

Hi,

I'm trying to sum up the distinct ID Count over 3 months and then divide in 3.

The issue is that I have to count each month first, then sum, then divide. 

very easy example:

distinct IDs in May=10,

distinct IDs in June=10,

distinct IDs in July= 10.

The average IDs over 3 months is 10. (the answer I'm after)

Could anyone help me and provide the correct syntax for this calculation?

 

 

1 Solution

Accepted Solutions
JordyWegman
Partner - Master
Partner - Master

Hi Meg,

It's still the same, but the syntax looks a bit harder:

Avg(
    Aggr(
       Count({$<PeriodCounter= {">=$(=max(PeriodCounter)-3) 
       <=$(=max(PeriodCounter)-1)"}, Year=, Month=, Period=, CalendarDate= ,
       [Category]={'D'} >}distinct ID)
    ,Month)
)

Jordy

Climber

Work smarter, not harder

View solution in original post

4 Replies
JordyWegman
Partner - Master
Partner - Master

Hi Meg,

Use this:

Avg(Aggr(Count(Distinct [ID]),[Month]))

The Count distinct will count the unique ID's. The Aggr will do this by month and the AVG will then get the average from this.

Jordy

Climber 

Work smarter, not harder
Meg00
Contributor III
Contributor III
Author

Unfortunately it does not work with my current syntax that now looks like this:

Count({$<PeriodCounter= {">=$(=max(PeriodCounter)-3)<=$(=max(PeriodCounter)-1)"}, Year=, Month=, Period=, CalendarDate= ,[Category]={'D'} >}distinct ID)

 

any ideas?

JordyWegman
Partner - Master
Partner - Master

Hi Meg,

It's still the same, but the syntax looks a bit harder:

Avg(
    Aggr(
       Count({$<PeriodCounter= {">=$(=max(PeriodCounter)-3) 
       <=$(=max(PeriodCounter)-1)"}, Year=, Month=, Period=, CalendarDate= ,
       [Category]={'D'} >}distinct ID)
    ,Month)
)

Jordy

Climber

Work smarter, not harder
Meg00
Contributor III
Contributor III
Author

Yes!:)

I forgot to put month in.

Thank you!