Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
AWS Degraded - You may experience Community slowness, timeouts, or trouble accessing: LATEST HERE
cancel
Showing results for 
Search instead for 
Did you mean: 
Evan0211
Creator II
Creator II

Getting the count of a filter from an if statement

I have a set of data that I am using to build a table. In that table, there are initial dates and completed dates. I have written an if statement to assign a new column to the table with a label that corresponds to the dates to state if it is on time or late

 

ex: If(not isnull([Revised Date]) and (Date([Revised Date]) < Today() and isnull([Completed Date])), 'Late'

This works as intended. Now I need to display a count of the items that are late and a count of the items that are on time in a KPI. How do I count all of the conditions that fall within each if statement?

Labels (1)
2 Replies
BrunPierre
Partner - Master II
Partner - Master II

Hi, Using a Count If()

=Count(DISTINCT If(not IsNull([Revised Date]) and (Date([Revised Date]) < Today() and IsNull([Completed Date])), Items))

or

Set Analysis

=Count({<[Revised Date]={"<$(=Date(Today()))"},[Completed Date]={"=Len(Trim([Completed Date]))=0"},[Revised Date]={"=Len(Trim([Revised Date]))<>0"}>} DISTINCT Items)

barnabyd
Partner - Creator III
Partner - Creator III

G'day @Evan0211,

@BrunPierre's solution is correct but I would like to suggest an improvement. It is more efficient to if you create your extra column in the load script and the use that column in the Set Analysis.

The most efficient is to create a flag like this ...

If( not isnull([Revised Date]) 
    and (Date([Revised Date]) < Today() 
    and isnull([Completed Date])), 1, 0 ) as isLate

Then your Set Analysis looks like this ... 

count( {$<isLate={1}>} distinct Item )

I hope this helps.

Cheers, Barnaby.

Barnaby Dunn
BI Consultant