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: 
ecabanas
Creator II
Creator II

Conditional count if

Hi,

I'm creating a table with the margin of the orders_:

SALESID     MArgin

A                   10

B                    -5

C                    7

Where Margin is a calculated field: Sales - Cost

I wanna know how many orders are posite or negative and I applied this formula, but it give me an error:

Count(Distinct IF([Margin]>='0', SALESID))

any knows why?

Many thank's

Eduard

9 Replies
sinanozdemir
Specialist III
Specialist III

How about this:

Count({<[Margin] = {">=0"}>} Distinct SALESID)

I also realized that in your formula you are using '0' as text, not as a number 0

sunny_talwar

Try it without the single quotes

and are you counting SALESID or ORDERID? Make sure to use the correct field name

=Count(Distinct If(Margin >= 0, SALESID))

or

=Count(Distinct If(Margin >= 0, ORDERID))

ecabanas
Creator II
Creator II
Author

did not works 😞

ecabanas
Creator II
Creator II
Author

Hi

I'm counting SalesId, sorry, but the formula did not works returns to me independently if Margin is positive or negative

sunny_talwar

Margin is a field which is getting calculated in the script? We both are assuming that it is, if it is not, then we might need to use other fields.

ecabanas
Creator II
Creator II
Author

Hi Sunny

No, the margin is calculated in the table not in the script

Dimension: SalesID

Margin= Sales - Cost 

Many thank's

sunny_talwar

Try this:

=Count(Distinct If((Sales - Cost) >= 0, SalesID))

maxgro
MVP
MVP

count( {$ <SALESID={"=Sales>Cost"}>} SALESID)

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

The Margin chart column may not be used in a aggregation function count(). You will need to repeat the expressions that computed the Margin.

-Rob