Here’s your expression, reformatted to my taste for clarity:
IF(
(LEFT([Barcode], 2) <> "25"),
IFS(
(LOOKUP([Barcode], “Master Data”, “Barcode”, “Average Cost”) >= 0.50),
(
LOOKUP([Barcode], “Master Data”, “Barcode”, “Average Cost”)
+ (
LOOKUP([Barcode], “Master Data”, “Barcode”, “Average Cost”)
* LOOKUP([Barcode], “Customers”, “Customer”, “Percentage”)
)
),
(LOOKUP([Barcode], “Master Data”, “Barcode”, “Average Cost”) = 0),
1000,
(LOOKUP([Barcode], “Master Data”, “Barcode”, “Average Cost”) < 0.50,
(
LOOKUP([Barcode], “Master Data”, “Barcode”, “Average Cost”)
+ 0.02
)
),
IFS(
(LOOKUP(LEFT([Barcode], 7), “Master Data”, “Barcode”, “Average Cost”) >= 0.50),
(
LOOKUP(LEFT([Barcode], 7), “Master Data”, “Barcode”, “Average Cost”)
+ (
LOOKUP(LEFT([Barcode], 7), “Master Data”, “Barcode”, “Average Cost”)
* LOOKUP(LEFT([Barcode], 7), “Customers”, “Customer”, “Percentage”)
)
),
(LOOKUP(LEFT([Barcode], 7), “Master Data”, “Barcode”, “Average Cost”) = 0),
1000,
(LOOKUP(LEFT([Barcode], 7), “Master Data”, “Barcode”, “Average Cost”) < 0.50),
(
LOOKUP(LEFT([Barcode], 7), “Master Data”, “Barcode”, “Average Cost”)
+ 0.02
)
)
)
Your use of [Barcode] within your LOOKUP() expressions is probably not doing what you want. Read the help doc for details:
Here’s the corrected expression:
IF(
(LEFT([Barcode], 2) <> "25"),
IFS(
(LOOKUP([_THISROW].[Barcode], “Master Data”, “Barcode”, “Average Cost”) >= 0.50),
(
LOOKUP([_THISROW].[Barcode], “Master Data”, “Barcode”, “Average Cost”)
+ (
LOOKUP([_THISROW].[Barcode], “Master Data”, “Barcode”, “Average Cost”)
* LOOKUP([_THISROW].[Barcode], “Customers”, “Customer”, “Percentage”)
)
),
(LOOKUP([_THISROW].[Barcode], “Master Data”, “Barcode”, “Average Cost”) = 0),
1000,
(LOOKUP([_THISROW].[Barcode], “Master Data”, “Barcode”, “Average Cost”) < 0.50,
(
LOOKUP([_THISROW].[Barcode], “Master Data”, “Barcode”, “Average Cost”)
+ 0.02
)
),
IFS(
(LOOKUP(LEFT([_THISROW].[Barcode], 7), “Master Data”, “Barcode”, “Average Cost”) >= 0.50),
(
LOOKUP(LEFT([_THISROW].[Barcode], 7), “Master Data”, “Barcode”, “Average Cost”)
+ (
LOOKUP(LEFT([_THISROW].[Barcode], 7), “Master Data”, “Barcode”, “Average Cost”)
* LOOKUP(LEFT([_THISROW].[Barcode], 7), “Customers”, “Customer”, “Percentage”)
)
),
(LOOKUP(LEFT([_THISROW].[Barcode], 7), “Master Data”, “Barcode”, “Average Cost”) = 0),
1000,
(LOOKUP(LEFT([_THISROW].[Barcode], 7), “Master Data”, “Barcode”, “Average Cost”) < 0.50),
(
LOOKUP(LEFT([_THISROW].[Barcode], 7), “Master Data”, “Barcode”, “Average Cost”)
+ 0.02
)
)
)
This analogy is entirely correct:
So all of those LOOKUP() expressions are slowing down the computation, and the slowdown will get worse as your app accumulates data. We need to find a better way (that doesn’t rely on a non-existent LET() function).
Because you need to use several column values from the looked-up rows, we’ll need a way to lookup and remember the row, so we can access the several column values without looking-up the row for each. To remember the looked-up row, we should capture it in a (preferably normal, not virtual) column. I’ll call the column Master Data, with an App formula of:
ANY(
IF(
(LEFT([Barcode], 2) <> "25"),
FILTER(“Master Data”, ([_THISROW].[Barcode] = [Barcode]),
FILTER(“Master Data”, (LEFT([_THISROW].[Barcode], 7) = [Barcode]),
)
)
With this in place, we can optimize your original expression further:
IFS(
([Master Data].[Average Cost] >= 0.50),
(
[Master Data].[Average Cost]
+ (
[Master Data].[Average Cost]
* IF(
(LEFT([Barcode], 2) <> "25"),
LOOKUP([_THISROW].[Barcode], “Customers”, “Customer”, “Percentage”),
LOOKUP(LEFT([_THISROW].[Barcode], 7), “Customers”, “Customer”, “Percentage”)
)
)
),
([Master Data].[AverageCost] = 0),
1000,
([Master Data].[Average Cost] < 0.50),
([Master Data].[Average Cost] + 0.02)
)
We could also capture the customer’s row as we did the Master Data row, in a column I’ll call Customer:
ANY(
IF(
(LEFT([Barcode], 2) <> "25"),
FILTER(“Customers”, ([_THISROW].[Barcode] = [Customer]),
FILTER(“Customers”, (LEFT([_THISROW].[Barcode], 7) = [Customer])
)
)
Back to the optimized original expression:
IFS(
([Master Data].[Average Cost] >= 0.50),
([Master Data].[Average Cost] + ([Master Data].[Average Cost] * [Customer].[Percentage])),
([Master Data].[Average Cost] = 0),
1000,
([Master Data].[Average Cost] < 0.50),
([Master Data].[Average Cost] + 0.02)
)
Myself, I’d structure it this way:
IFS(
([Master Data].[Average Cost] >= 0.50),
([Master Data].[Average Cost] + ([Master Data].[Average Cost] * [Customer].[Percentage])),
([Master Data].[Average Cost] > 0.0),
([Master Data].[Average Cost] + 0.02),
TRUE,
1000
)
Consider similarly optimizing the other columns you have that use the barcode value. You can re-use the Master Data and Customer columns we created here for the others.