cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SErgey-kuznetso
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.
 
Screenshot_44.png
1 ACCEPTED SOLUTION
mussaenda
Resident Rockstar
Resident Rockstar

Hi @SErgey-kuznetso ,

 

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

View solution in original post

2 REPLIES 2
mussaenda
Resident Rockstar
Resident Rockstar

Hi @SErgey-kuznetso ,

 

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

View solution in original post

Marik
Solution Supplier
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.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.