Forum Discussion

Elie_HUCHET's avatar
Elie_HUCHET
Helper III
1 year ago
Solved

Formula problem

Hello,
I'm writing to you because I have a major formula problem.
In my formula, which you'll see below, I'm trying to recalculate a route order  (N° Ordre de ligne) for customers who are "Sur appel".
Therefore, customers after this type of customer are assigned a -1 on their scheduling order.
Customers before this event are not affected. However, my formula applies this subtraction to all customers, and I can't find a solution. If someone could help me, please.

2.9 OrdrePlanifie =
VAR OrdrePlanifieActuel = SELECTEDVALUE(FAIT_CLEAR_UO_Planif[No Ordre ligne])
VAR FrequenceActuelle = SELECTEDVALUE(FAIT_CLEAR_UO_Planif[Fréquence theorique])
VAR StatutPresence = [1.0 Contrôle présence client]

-- Sur appel si fréquence vide
VAR FrequenceVideActuelle =
    IF(
        FrequenceActuelle = BLANK(),
        "Sur appel",
        SELECTEDVALUE(FAIT_CLEAR_UO_Planif[No Ordre ligne])
    )

-- Rechercher un dossier sur appel précédent
VAR DossierSurAppel =
    CALCULATE(
        MAX(FAIT_CLEAR_UO_Planif[No Ordre ligne]),
        FILTER(
            ALL(FAIT_CLEAR_UO_Planif),
            Mesures[1.0 VérificationSurAppel] = "Sur appel"
            && FAIT_CLEAR_UO_Planif[No Ordre ligne] < OrdrePlanifieActuel
        )
    )

RETURN
SWITCH(
    TRUE(),

    -- Cas BI en plus sans ordre planifié
    StatutPresence = "BI en plus" && ISBLANK(OrdrePlanifieActuel), "BI en plus",

    -- Cas BI en moins
    StatutPresence = "BI en moins", OrdrePlanifieActuel,

    -- Cas sur appel
    FrequenceVideActuelle = "Sur appel", "Sur appel",

    -- Cas BI en plus avec ordre planifié
    StatutPresence = "BI en plus" && NOT ISBLANK(DossierSurAppel)
        && OrdrePlanifieActuel > DossierSurAppel, OrdrePlanifieActuel - 1,

    -- Cas classique avec un précédent sur appel : appliquer -1 uniquement si après
    NOT ISBLANK(DossierSurAppel)
        && OrdrePlanifieActuel > DossierSurAppel, OrdrePlanifieActuel - 1,

    -- Cas par défaut
    OrdrePlanifieActuel
)

There are a lot of terms in French, so if you need clarification or additional information, don't hesitate to ask!
Thank you again for your time.

1 Reply