Common operators in Factory formulas
The following common operators are supported in Rulex formulas:
Operator Symbol | Function | Examples |
---|---|---|
“ “ | String delimiter. Strings are always enclosed in quotation marks, and can contain any characters. | “Sales Trend”, “This is a complicated \t string $5%msd\n” |
$ | Identifies a column/attribute in a dataset | shift($"Weekly_Sales",1,$"Store") |
( ) | List parenthesis. Brackets can be used in 2 main ways:
| $”discount” * ($”cost” + $“VAT”) sum(($”Monday_sales”, $”Tuesday_sales”, $”Wednesday_sales”)) |
, | The comma separates parameters in a list. | sum(($”Monday_sales”, $”Tuesday_sales”, $”Wednesday_sales”)) |
: | The colon indicates a range between columns. It must be used as part of a list, and consequently be delimited by brackets. | sum(($”Monday_sales” : $”Wednesday_sales”)) |
- | Minus operator. | $”Difference in cost" = $”Cost of oranges today"-$”Yesterday's cost" |
+ | Plus operator. | $”Transport Cost” = $”Petrol Cost” + $”Motorway Charges” |
* | Product operator. | $“Total Sales of Item1” = $”Item1 Sold” * $”Item1 Cost” |
^ | Power operator | $”Area square room” = $”Length wall”^2 |
< | Less than angle bracket | $”SalesTrend” = ifelse($"Weekly Sales” < $"Last Week Weekly Sales”,"Decrease",Increase”) |
> | Greater than angle bracket | $”SalesTrend”= ifelse($"Sales Difference"> 0,"Increase","Decrease") |
!= | Does not equal, is different from. When it is used with None values, it can’t manage them, so it returns an empty cell. | $”Type of year” = ifelse($"DaysInYear" != 365,$”LeapYear”, $”Normal Year”) |
\ | Backslash is the escape character and it has 2 uses inside a string:
If we want to insert a real backslash in a string, itself must be escaped ( \\ ) | $“Monthly \”deals” “This string must be\non two lines” means start a new line “I want to print backslash \\ “ |
/ | Division operator | $”Transport Cost per Truck” = $”Transport Cost” / $”Number of Trucks” |
== | Equals in comparisons. The “=” symbol, which assigns a value, is inserted automatically between the left and right side of the formula by Rulex. When dealing with the None value, the == symbol returns a binary True or False in any case, when dealing with nominal values. | $”Item Cost” == 5 |
% | Modulo operator (it evaluates the rest in a division) | $”Money of Tip” = $”Total Payed” % $”Bill cost” |
The following operators are expressed as words:
Operator Word | Function | Examples |
---|---|---|
is | Equals to. This operator is different from the “==” symbol because it returns a binary True or False value in any case with any attribute type. This is particularly important when dealing with the None value. |
Whereas:
|
not is | Does not equal, is different from. This operator is different from the “!=” symbol because it returns a binary True or False value in any case. This is particularly important when dealing with the None value. |
Whereas:
|
in | This operator returns a binary value. It returns True for any element of the first column which is contained in the second column. | $”MyFavouriteColor” in $”HerFavouriteColor” will return True for all the entries in $”MyFavouriteColor” attribute which are inserted also in $”HerFavouriteColor” attribute and False for the other ones. |
not | Does not equal, is different from. This operator is different from the “!=” symbol because it precedes an argument, it’s not used to build it. | $”Type of year” = ifelse(not ($"DaysInYear" == 365),$”LeapYear”, $”Normal Year”) |
and | This operator returns a binary True or False value. It returns True if the two conditions are both true. It returns False if even one of the conditions is false. The and operator implies that both the conditions set have to be satisfied, in order to have True as a result. | $”IsMyCar” = $”NameOwner” == $”MyName” and $”SurnameOwner” == $”MySurname” |
or | This operator returns a binary True or False value. It returns True if at least one of the conditions is true. It returns False if both the conditions are false. The or operator implies that at least one of the conditions set has to be satisfied, in order to have True as a result. | $”IsBirthday” = $”Today” == $”BirthdayDate” or $”YesterdayAge” != $”TodayAge” |
Strings can contain any characters, but must always enclosed with the symbol “. For example, “sales”.
Variable names can contain letters (capital and small), numbers and underscore only.