Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
kaisdeco
Contributor II
Contributor II

Count Distinct IF (Conditions based on variables)

I know you've already posted similar cases and gotten answers. Based on them I have been able to solve some issues that I had but still present one.

I have to count some codes of the current year and in the corresponding month when the difference between two dates is 0.

This is the code that has issues:

COUNT(DISTINCT(IF($(DIFF_YEAR) = 0 AND [YEAR] = {'CYTD'} AND MONTH = $(=MONTH_NO), CODE)))

When I use the following instruction it works:
COUNT(DISTINCT(IF($(DIFF_YEAR) = 0, CODE)))

But when I add AND [YEAR] = {'CYTD'}  and MONTH = $(=MONTH_NO). Does not show results.

Thank you for your help.

Labels (1)
10 Replies
kaisdeco
Contributor II
Contributor II
Author

Hi guys,

 

Thank you for your help. I'd like to share with you that I got the info that I needed so far.

I used this sentence and it's working:

COUNT( DISTINCT( IF( $(DIFF_YEAR) = 0 AND YEAR = 'CYTD' AND MTH_NO = $(=MONTH_NO), INFORCE_POL_NO)))

I was checking the month values when you (Kush) asked me and I found that I was taking a bad field MONTH and I have to take  MTH_NO.