WF7A

More elegant way of coding this calculation

5 posts in this topic

Posted (edited)

Greets, all:

 

I know there's a more elegant way of coding this part of a Let calc but I'm having a brain fade:

Let ( [

Country = CountryAbbreviated1__lxt ;

State1 = StateAbbreviated1__lxt

] ;

Case (
    Country = "CA" and State1 = "NU";
    "Territory";
    Country = "CA" and State1 = "NT";
    "Territory";
    Country = "CA" and State1 = "YT";
    "Territory"
         )

)

 

What is it? The Evaluate command?

Thanks, and cheers,

Rich

 

 

Edited by WF7A

Share this post


Link to post
Share on other sites

Posted (edited)

You could write simply:

If ( CountryAbbreviated1__lxt = "CA" and ( StateAbbreviated1__lxt = "NU" or StateAbbreviated1__lxt = "NT" or StateAbbreviated1__lxt = "YT" ) ; "Territory" )

Or, if you prefer a shorter version:

If ( CountryAbbreviated1__lxt = "CA" and not IsEmpty ( FilterValues ( StateAbbreviated1__lxt ; "NU¶NT¶YT" ) ) ; "Territory" )

 

I see no good reason to use the Let() function only to rename your fields. I also don't see a good reason to use such gobbledygook field names to begin with. And the numeric suffixes raise a red flag: if you're using numbered fields, you almost certainly have a structural issue.

 

Edited by comment
2 people like this

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks! Yes, if there's one thing I excel at it's making things vastly more complicated than they should be. (Hey, everybody has a skill.)

I should rename those fields--although they're not number fields (they're text fields), they're currently two sets of state and country fields in the same table and layout: "1" is for a company's HQ  and "2" is for its remote site; better names, for example, would be CountryAbbreviated_HQ and CountryAbbreviated_Remote.

Edited by WF7A

Share this post


Link to post
Share on other sites

The same principle holds; a company can have a variable number of remotes.  So the locations could be it's own table and the 'hq' or 'remote' becomes just an attribute of the.location.

Share this post


Link to post
Share on other sites

Posted (edited)

That would be true except that for each record (and therefore, company name) there there would only be one HQ and only one remote site (if any), irrespective of how many remote sites there might actually be; if there is a remote site, the user can only enter one. (90% of the time there wouldn't be one.)

Edited by WF7A

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now