Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Elie_HUCHET
Helper III
Helper III

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 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors