views:

103

answers:

2

I want to add a second Address field into this custom function (ie. Apt. #101). If you wanted, you could explain how the Case(not IsEmpty works and I would be willing to attempt to add the second address field in myself...

Let(
[
    x1 = Name;
    x2 = x1 & Case(not IsEmpty(Address); Case(not IsEmpty(x1); "¶") & Address);
    x3 = Case(not IsEmpty(City); City & ", ") & Case(not IsEmpty(State); Upper ( State ) & " ") & Zip;
    x4 = x2 & Case(not IsEmpty(x3); "¶") & x3;
    x5 = x4 & Case(not IsEmpty(Country); Case( not IsEmpty(x4); "¶") & Country)
];

    x5

)
+1  A: 
Let( [

   x1 = Customer::FullName;
   x2 = x1 & Case(not IsEmpty(Address1); Case(not IsEmpty(x1); "¶") & Address1);
   x3 = x2 & Case(not IsEmpty(Address2); Case(not IsEmpty(x2); "¶") & Address2);
   x4 = Case(not IsEmpty(City); City & ", ") & Case(not IsEmpty(State); Upper ( State ) & " ") & ZipCode;
   x5 = x3 & Case(not IsEmpty(x4); "¶") & x4 ];

x5

)
Ryan
A: 

I'd recommend doing away with the let statement, it seems to make it more confusing. The end goal is, you want to concatenate a bunch of address values together. If an address value is not empty, you want to put a line break (or a comma + space, for the city) after the element in question. Something like this:

LeftWords (
    Case (not IsEmpty(Customer::FullName) ; Customer::FullName & "¶" ) &
    Case (not IsEmpty(Address1) ; Address1 & "¶" ) &
    Case (not IsEmpty(Address2) ; Address2 & "¶" ) &
    Case (not IsEmpty(City) ; City & ", " ) &
    Case (not IsEmpty(State) ; Upper (State ) & " " ) &
    ZipCode
; 9999 )

The LeftWords function with an arg of 9999 (or some other suitably large value) removes any trailing newline or whitespace, which could happen if city, state, and zip are all empty.

Sam Barnum