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: 
Stanislav1
Contributor II
Contributor II

Aggr() function with month for distinct count over the months

Hello there!

I am struggling for a while with this one and I need your help. I want to see the distinct count per month for Campaign ID in a line chart using aggr function.

I have this so far: Max(Aggr(Count( {<$(v_SA_Calendar_Dynamic)>} distinct[Campaign Id]),[Date Start]))

Stanislav1_0-1667936247207.png

The above number (31) is the total campaigns for 2021 and on the bottom you can see the line chart where for some reason the total count is 36 not 31. 

Labels (2)
1 Solution

Accepted Solutions
rubenmarin

You can add a table with Month, campaign id and start date and see the relation between these fields, I suppose each campaign id would have only one start date.

Maybe is just: Count(Distinct If(Month=Month([Date Start]), [Campaign Id])

View solution in original post

4 Replies
rubenmarin

Hi, that could be because some of the campaigns will count for more than one month, this could happen if the month field used in chart is not directly associated with the Date start, maybe it comes from the sales month or other field where one campaign could be in more than one month.

In this case, maybe: 

Count({<$(v_SA_Calendar_Dynamic)>} distinct Aggr(If(Month=Month([Date Start]), [Campaign Id]),Month,[Campaign Id]))

Stanislav1
Contributor II
Contributor II
Author

Hi, you are completely correct. Some of the campaigns are in more than one month. I tried your solution: 

Count({<$(v_SA_Calendar_Dynamic)>} distinct Aggr(If(Month=Month([Date Start]), [Campaign Id]),Month,[Campaign Id]))

Still no success here. 

Stanislav1_0-1667985997352.png

 

rubenmarin

You can add a table with Month, campaign id and start date and see the relation between these fields, I suppose each campaign id would have only one start date.

Maybe is just: Count(Distinct If(Month=Month([Date Start]), [Campaign Id])

Stanislav1
Contributor II
Contributor II
Author

The issue is resolved thank you