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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
sotw90
Contributor
Contributor

Counting a field distinct in current year and month

Hello, i have been trying over the past week to make a formula that would count distinct the customer field only when the order amount is bigger than 0 (if it's 0 it shouldn't count at all) and i need this for current year and current month. 

This is as far as i got so far: 

count(

{<Customer=
{"=Sum({<Year={$(=Year(Today()))}>} AND {<Month={$(=NUM(Month(Today())))}>} SUM(OrderAmount)) > 0"}, Year={$(=Year(Today()))}
,Month={$(=Num(Month(Today())))}
>}

DISTINCT Customer)

This only seems to work if i put year only or month only but when both conditions are there it just shows 0, i tried making avariable called YearMonthInt to show something like 201808 but that doesn't seem to work either. 

Any advice would be appreciated. 

Labels (2)
1 Solution

Accepted Solutions
sunny_talwar

Try this

Count({<Customer = {"=Sum({<Year = {$(=Year(Today()))}, Month ={$(=Num(Month(Today())))}>} OrderAmount) > 0"}, Year = {$(=Year(Today()))}, Month = {$(=Num(Month(Today())))}>} DISTINCT Customer)

View solution in original post

2 Replies
sunny_talwar

Try this

Count({<Customer = {"=Sum({<Year = {$(=Year(Today()))}, Month ={$(=Num(Month(Today())))}>} OrderAmount) > 0"}, Year = {$(=Year(Today()))}, Month = {$(=Num(Month(Today())))}>} DISTINCT Customer)
sotw90
Contributor
Contributor
Author

This worked!!, thank you very much!