This is a code that I am writing with the purpose of calculating the latest date of my company’s spare parts used, however, I would like to check certain conditions,

SP_USED[Product Number] = “92360122” OR SP_USED[Product Number] = “92360136” with their model numbers being either :

        SP_USED[Model Number (Adjusted)] = "XN-10" ||
        SP_USED[Model Number (Adjusted)] = "XN-20" ||
        SP_USED[Model Number (Adjusted)] = "XN-31" ||
        SP_USED[Model Number (Adjusted)] = "XR-10" ||
        SP_USED[Model Number (Adjusted)] = "XR-10"

I wrote a code which produces the wrong output (does not take into consideration the filtered table base on conditions and returning the max, instead it returns a max over all of the rows without filtering)
Code 1:

LUsedDateCombined =
VAR currIB = SP_USED[Install Base]
VAR maxDateLastUsed =
CALCULATE(
MAX(SP_USED[BRB Start Date]),
FILTER(
SP_USED,
SP_USED[Product Number] = “92360122” || SP_USED[Product Number] = “92360136” &&

        SP_USED[Model Number (Adjusted)] = "XN-10" ||
        SP_USED[Model Number (Adjusted)] = "XN-20" ||
        SP_USED[Model Number (Adjusted)] = "XN-31" ||
        SP_USED[Model Number (Adjusted)] = "XR-10" ||
        SP_USED[Model Number (Adjusted)] = "XR-10"
    
),
SP_USED[Install Base] = currIB 

)
RETURN
FORMAT(maxDateLastUsed, “dd/mm/yyyy”)


But once I add the parenthesis, it returns the corr output, giving me the max date based on my filtered conditions

Code 2:

LUsedDateCombined (Joanne) =
VAR currIB = SP_USED[Install Base]
VAR maxDateLastUsed =
CALCULATE(
MAX(SP_USED[BRB Start Date]),
FILTER(
SP_USED,
SP_USED[Product Number] = “92360122” || SP_USED[Product Number] = “92360136” &&

        (SP_USED[Model Number (Adjusted)] = "XN-10" ||
        SP_USED[Model Number (Adjusted)] = "XN-20" ||
        SP_USED[Model Number (Adjusted)] = "XN-31" ||
        SP_USED[Model Number (Adjusted)] = "XR-10" ||
        SP_USED[Model Number (Adjusted)] = "XR-10")
    
),
SP_USED[Install Base] = currIB 

)
RETURN
FORMAT(maxDateLastUsed, “dd/mm/yyyy”)

What could possibly be the cause?

After I realized this, I tried to put parenthesis in the first condition and remove parenthesis in the second, but it gives me the wrong output, I dont understand why the parenthesis and its position changes things.

New contributor

Joanne Jeow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.