Use lookup tables instead of multiple nested “IF” statements

Every now and then I come across a customer who has created an EasyMorph expression comprising a large number of “IF” statements or functions nested inside each other. Something like this:

if([ProductGroup]="Chess", "Board Games",
    if([ProductGroup]="Monopoly", "Board Games",    
        if([ProductGroup]="Mouse Trap", "Board Games",
            if([ProductGroup]="Uno", "Card Games",
                if([ProductGroup]="Playing Cards", "Card Games", 
                    if([ProductGroup]="Playing Cards", "Bikes, Scooters & Karts", "Other")
                )
            )
        )
    )
)

Slap this in a “Calculate new column(s)” action and you have your additional data field.

There is nothing technically wrong with doing this approach and it will achieve what you want. But the above is just a small example and I’ve seen expressions comprising several hundred nested IFs. Trying to update them or picking them apart when something isn’t working becomes a time consuming job.

An alternative way to achieve the same result (with a lot less headache) is to create a lookup table containing the mappings. You can use any file format or even a database table to hold your mapping - whichever is the easiest for you to maintain.

ProductGroup ProductClass
Chess Board Games
Monopoly Board Games
Uno Card Games
..... .....

We can then load this lookup table into our EasyMorph workflow and use the “Lookup” action to use it to add the additional column to our data table:

There’s no notable performance difference between the 2 methods, and updating a table in a CSV or Excel spreadsheet is a lot simpler than trying to wrangle hundreds of nested IF statements and to work out where you might have missed a comma or a bracket.

There are many ways how to create and maintain lookup tables. For instance:

  • Embedded lookup table in the workflow using the "Create list" action (up to 1000 rows)
  • EasyMorph .dset file (use Dataset Editor to edit it, good for tables with up to 1 million records)
  • Spreadsheet (Excel or Google Sheet)
  • Text file (e.g. CSV)
  • Database table
  • SharePoint List
  • Airtable

I think the Rules action is also a good alternative where it’s just easier to comprehend a nested IF formula.

Agree that lookup tables are more flexible.

That's a very good point. The "Rule" action was designed exactly to replace nested IFs.