# COUNTIF in rules

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

• # COUNTIF in rules

Hi All,
How do I replicate the COUNTIF in rules. eg count number of elements in a cube with value over 100.
• # RE: COUNTIF in rules

In simple terms you don't

The workaround is that you create a new variable and you write a conditional rule,

So for example if you have Sales and you want to count how many instance are > 100 you create a new element Sales Count and you write a rule that says.

["Salescount"] = N: if(["Sales"] > 100,1,0)

This variable will then consolidate naturally to give you what you need.

Hope this helps
Best wishes

John Hobson
The Planning Factory, Lytham, UK
www.planfact.co.uk

The post was edited 1 time, last by Pommie ().

• # RE: COUNTIF in rules

Thanks Pommie. That will work for me
• wow, old post but still useful though...

I had the same problem but I wanted to count if the field equals some value... For example, the number of "Yes" or "No"

So I tried this:

["CountOfYes"] = N: IF(["YesOrNoQuestion"] = "Yes",1,0)

YesOrNoQuestion being a String-Typed element

It did not work. The rule editor does not seem to accept the "=" in the formula.

So I used this workaround:

["CountOfYes"] = N: IF(EXACT["YesOrNoQuestion"], "Yes",1,0)

And it works.

Hope it helps!
laloune

Post hoc, non est propter hoc
• ["CountOfYes"] = N: IF(["YesOrNoQuestion"] = "Yes",1,0)

I think that might have worked if you had used the double =

as in

["CountOfYes"] = N: IF(["YesOrNoQuestion"] == "Yes",1,0)
Best wishes

John Hobson
The Planning Factory, Lytham, UK
www.planfact.co.uk
• oh man, that's right !

like it is said in a famous french cartoon (poorly translated though): "why doing something the simple way when you can do it the complicated way ?"

Thanks !
laloune

Post hoc, non est propter hoc
• No wories - the == catches me out regularly

I'm sure there is a logic as to why the first = is just a single = but in the bodyof the rule it has to be ==, but whatever logic it is escapes me I'm afraid
Best wishes

John Hobson
The Planning Factory, Lytham, UK
www.planfact.co.uk
• == is a comparison operator in C, C++, ... (the palo server is programmed in these languages)

= is an assignment operator

the one-for-all way VBA does is bad IMO:

can easily bite you in conditional statements:
a = 6
means condition true if I can assign a the value 6 ??!!!

The post was edited 1 time, last by axi ().