cancel
Showing results for
Did you mean:
Frequent Visitor

## How to simplify and shorten a formula with the IF function?

Hi, everyone! I have such a huge formula (in fact, it is much longer, about 80 lines, I shortened it here so that you can understand the essence). How can I make it more compact? Please advise any functions or solutions for this.

company_part =
IF (
DBExtras[name] = "Child chair (group 1)", DBExtras[price] / 2,
IF (
DBExtras[name] = "Booster (group 2/3)", DBExtras[price] / 2,
IF (
DBExtras[name] = "Infant seat (cradle)", DBExtras[price] / 2,
IF (
DBExtras[name] = "SIM card" && DBExtras[currency]="EUR", DBExtras[count] * 2,
IF (
DBExtras[name] = "SIM card" && DBExtras[currency]="USD", DBExtras[count] * 2,
IF (
DBExtras[name] = "SIM card" && DBExtras[currency]="RUB", DBExtras[count] * 120,
IF (
DBExtras[name] = "Drinking water" && DBExtras[currency]="EUR", DBExtras[count] * 1,
IF (
DBExtras[name] = "Drinking water" && DBExtras[currency]="USD", DBExtras[count] * 1,
IF (
DBExtras[name] = "Drinking water" && DBExtras[currency]="RUB", DBExtras[count] * 70

I use this formula to calculate, depending on the service and its cost in different currencies, which part our company receives and which part we give to partners. Below you can see the data model.

1 ACCEPTED SOLUTION
Resident Rockstar

You can use the || together with () to shorten your formula.

I think you can also use switch as your option.

``````company_part =
SWITCH(
TRUE(),
(DBExtras[name] = "Child chair (group 1)" ||
DBExtras[name] = "Booster (group 2/3)" ||
DBExtras[name] = "Infant seat (cradle)"), DBExtras[price] / 2,

DBExtras[name] = "SIM card" &&
(DBExtras[currency]="EUR" ||
DBExtras[currency]="USD"), DBExtras[count] * 2,

DBExtras[name] = "SIM card" &&
DBExtras[currency]="RUB", DBExtras[count] * 120,

DBExtras[name] = "Drinking water" &&
(DBExtras[currency]="EUR" ||
DBExtras[currency]="USD"), DBExtras[count] * 1,

DBExtras[name] = "Drinking water" && DBExtras[currency]="RUB", DBExtras[count] * 70
``````
2 REPLIES 2
Resident Rockstar

You can use the || together with () to shorten your formula.

I think you can also use switch as your option.

``````company_part =
SWITCH(
TRUE(),
(DBExtras[name] = "Child chair (group 1)" ||
DBExtras[name] = "Booster (group 2/3)" ||
DBExtras[name] = "Infant seat (cradle)"), DBExtras[price] / 2,

DBExtras[name] = "SIM card" &&
(DBExtras[currency]="EUR" ||
DBExtras[currency]="USD"), DBExtras[count] * 2,

DBExtras[name] = "SIM card" &&
DBExtras[currency]="RUB", DBExtras[count] * 120,

DBExtras[name] = "Drinking water" &&
(DBExtras[currency]="EUR" ||
DBExtras[currency]="USD"), DBExtras[count] * 1,

DBExtras[name] = "Drinking water" && DBExtras[currency]="RUB", DBExtras[count] * 70
``````
Solution Supplier

@SErgey-kuznetso You can create additional dictionary table with two columns: DBExtras[name] and multiplifer; then through LOOKUPVALUE extract proper values without lots of IFs.

Announcements

#### Launching new user group features

Learn how to create your own user groups today!