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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors