Jump to content

Rule syntax help for calculating remainder of attribute


Recommended Posts

I am looking for syntax which tell me if  remainder of attribute after dividing the attribute with certain number is zero then valid 

how to write for remainder function in rulex formula file

e.g IF "Column A" > 0 [f] then "VALID" 

Like that I want if column A's remainder after dividing by 7 is zero then Valid

Edited by Pushkar
Link to comment
Share on other sites

Hi Pushkar, nice to meet you!
Before I answer your question about how to write the rule correctly, I would point out two stylistic and conceptual details in the syntax to apply to any rule:

  • IF and THEN is customary to always write them in uppercase, for better distinction between keywords and user-entered and therefore editable fields
  • If you want to check whether a rule is valid or not, for the Rule Engine you should always write the rule in such a way that it is checked for invalidity, this way 'Valid', 'Invalid' and 'Not Applicable' cases are automatically handled. Also, output values should be written in single quotes and not double quotes, unless you want to save them in a column, in which case the column name goes in double quotes and the value in single quotes (so in this case it will be to write 'INVALID' and not "INVALID").

As for the rule on the other hand, given these premises, the correct form to write it is: IF ("Column A"%7) != 0 [f] THEN 'INVALID'
Through the % operator in fact you can get the remainder of a division operation.
I hope I have dispelled all your doubts, if not, feel free to ask me for more information! Have a nice day!

Link to comment
Share on other sites

Hi Walter, Nice to connect with you again through this community forum!

Fantastic, really appreciate for your comment on Rule syntax. This is working well now.

I have one more doubt about [f] word written in that code: IF ("Column A"%7) != 0 [f] THEN 'INVALID' , how do you decide when to use it or not. In some syntax we don't see it.

Like when we == comparison I guess we don't need but some other operators we need it. In that case how one should decide and what's the goal of that [f].

Thanks! Have a great day:)

Link to comment
Share on other sites

Hi Pushkar, what you write is correct: the syntax with [f] turns out to be necessary only if you decide to apply any formula. This can be a comparison, through mathematical and logical operators (so "==", ">", "<", "!=", and so on), or should we want to apply any formula that Rulex allows to handle (simple examples can be the formulae "sum", "mean", "max", "min", and others).
Let me remind you that when using a formula, it is necessary to write the keyword [f] following the formula in question, separated by a space. The only cases in which you will not see [f] is when checking whether a column has a value that is part of a set, for which you then use the "in" operator (e.g., "Column A" in {'This value'}), in this case [f] is not required.
I hope I have made myself clear! Please, let me know if you have any other curiosities.
Thanks and have a nice day!👋

Link to comment
Share on other sites

Absolutely, understood it.Thanks!

Walter, Imagine I want to write a condition like below


CONDITION:  Column B should be either MISS/0 otherwise Column B >3 to be called as Valid.

I am writing something like this.

IF "COLUMN B" not in {'MISS','0'} WHEN WHEN "COLUMN A" in {'1'} THEN 'INVALID'

I am not getting desired result because it's going in loop one makes valid and another makes invalid. Any suggestion, how I can solve it.

Thanks in advance.


Link to comment
Share on other sites

Hi Pushkar! Firstly: is the COLUMN B a column with integer values? In that case I think that in the second rule after the OR should be: "COLUMN B" == 0 | "COLUMN B" is None [f] ; since as I remember to you, you are checking for the invalidity, so you have to put the contrary condition and if the column is an integer you cannot use the 'MISS' value to check the None (this is intended to be compiled like that only for the nominal column). In case it is a nominal column, it should be: "COLUMN B" in {'MISS','0'}. And I don't know if it was a typo, but in the second rule there are two "WHEN"!!

Have a nice weekend!

Link to comment
Share on other sites

Sorry WHEN was my typo error.

COLUMN B is integer but I converted to Nominal and replacing blank record with 'MISS'

Actually when we put  "COLUMN B" in {'MISS','0'} this is valid condition, that's why I wrote not in {'MISS','0'} but again it goes in loop to first rule.

e.g If column B has value 5 then it will be invalid due to 2nd rule but 1st rule will say it's valid.

when you say contrary condition, do you mean we can write Invalid in one line and Valid condition in 2nd?

IF "COLUMN B" == 0 | "COLUMN B" is None [f] WHEN "COLUMN A" in {'1'} THEN 'VALID'



Edited by Pushkar
Link to comment
Share on other sites

Hi again Pushkar!
Actually, your rule is not logically wrong, but if you don't put the label 'INVALID' the other cases are not managed (I mean 'Valid' and 'Not Applicable'). Anyway, I made a comprehension mistake, if your goal is to have 'Valid' when the "COLUMN B" is equal to 0 or 'MISS', then you have to write the rule like that:
IF "COLUMN B" != 0 AND "COLUMN B" not is None [f] WHEN "COLUMN A" in {'1'} THEN 'INVALID'

The reason why I use AND instead of OR, it because that's a pretty application of the De Morgan rule for the logical operator 😁
Let me know if now it works!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...