1

Looking for advice on how to implement a conditional formatting based on several factors. I'm still working on my Raw Materials Inspection app:

n

We have 2 factors to consider: Probation and Time.

If a supplier is "On Probation" their parts should be Inspected every time and the result in the purple box would be YES.

The second factor is time. A part may need to be inspected every XX days (the Frequency of Inspection). If the Last Inspected date + Frequency-in-Days is <=Today() then the part is due for inspection and the result would be YES in the green box above.

I had both of these scenarios covered in the following text formula (note: INSP-NOW represents the Probation status):

If((Today() >= DateAdd(ThisItem.'LAST-INSP',Value(ThisItem.'FREQ-IN-DAYS')))," INSPECTION DUE ", (ThisItem.'INSP-NOW'.Value="YES")," INSPECTION DUE "," ")

Now someone has introduced the proverbial monkey wrench into my conditional statement -- If the Frequency is set to zero, then the time test should be ignored (that is, if FREQ =0, only check if the supplier in on Probation).

PowerApps IF statement uses a format of

IF(test1,result1, [test2, result2,...,] default)

so do the logical test stop once a true is encountered -- that is, if test1 is true does the If statement ever process test2?

Do I use the Switch statement here instead?

Thanks,

gpence

1

From the docs: "Conditions and matches are evaluated in order, and they stop if a condition is true or a match is found."

Switch is good for when you're looking at one value that could have different options, and then taking different actions. But you have different conditions, so an if seems to be more appropriate here.

0

Thanks, @Mike2500 -- I did not see this reference in the documentation. I can now ask my conditions in a specific order and get it to work correctly. The IF statement is now formatted as:

If((ThisItem.'INSP-NOW'.Value="YES")," INSPECTION DUE ",(ThisItem.'FREQ-IN-DAYS'=0)," ",(Today()>=DateAdd(ThisItem.'LAST-INSP',Value(ThisItem.'FREQ-IN-DAYS')))," INSPECTION DUE "," ")

In English this equates to:

Test1: If the Probation flag is yes, then set the result to "Inspection Due" and stop processing,

Test2: If the Frequency-in-days is set to zero (and the Probation flag is OFF because Test1 did not match), then set the result to an empty string,

Test3: If the frequency plus the last inspection date is equal to or greater than today, set the result to "Inspection Due",

ELSE set result to null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.