March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Solved! Go to Solution.
Hi @PC2022 ,
The issue lies in the evaluation order of conditions within your SWITCH(TRUE(), ...) statement. The conditions are being evaluated sequentially, and some conditions (e.g., "On Schedule") are matching prematurely, causing unexpected results.
To fix this, adjust the order of conditions to prioritize the most specific ones first. Here's the corrected DAX formula:
SchKPI =
VAR DaysUntil = DATEDIFF(TODAY(), msdyn_projecttask[Finish], DAY)
VAR ScheduleStatus = SWITCH(
TRUE(),
// Off Schedule: % Complete < 100, past due, or Finish > Baseline Finish
(msdyn_projecttask[% Complete] < 100 && DaysUntil < 0) || msdyn_projecttask[Finish] > msdyn_projecttask[Baseline Finish], "Off Schedule",
// On Watch: % Complete < 100 and Finish is within 45 days from today
msdyn_projecttask[% Complete] < 100 && DaysUntil < 45, "On Watch",
// On Schedule: % Complete = 100 and Finish <= Baseline Finish
msdyn_projecttask[% Complete] = 100 && msdyn_projecttask[Finish] <= msdyn_projecttask[Baseline Finish], "On Schedule",
// On Schedule: Finish <= Baseline Finish
msdyn_projecttask[Finish] <= msdyn_projecttask[Baseline Finish], "On Schedule",
// On Schedule: Finish is in the future
msdyn_projecttask[Finish] > TODAY(), "On Schedule",
// Default case for debugging
"Error"
)
RETURN ScheduleStatus
Let me know if this resolves your issue or if you need further clarification!
Best regards,
I used your sequence but unfortunately it didn't work. See screen shot below, it marked all task red. I tried moving "on watch" on top, it marked all tasks yellow.
Hi @PC2022 ,
Try the expression and if it still doesn't work, please share the sample file:
SchKPI =
VAR DaysUntil = DATEDIFF(TODAY(), msdyn_projecttask[Finish], DAY)
VAR ScheduleStatus = SWITCH(
TRUE(),
msdyn_projecttask[Baseline Finish] = BLANK(), BLANK(),
msdyn_projecttask[% Complete] = 100 && msdyn_projecttask[Finish] <= msdyn_projecttask[Baseline Finish], "On Schedule",
msdyn_projecttask[% Complete] < 100 && DaysUntil < 0, "Off Schedule",
msdyn_projecttask[% Complete] < 100 && DaysUntil < 45, "On Watch",
msdyn_projecttask[Finish] <= msdyn_projecttask[Baseline Finish], "On Schedule",
msdyn_projecttask[Finish] > TODAY(), "On Schedule",
"Error"
)
RETURN ScheduleStatus
Hope it helps!
Best regards,
Community Support Team_ Scott Chang
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
I replaced "100" with "1" and it worked.
Thank you but it didn't work. How do i share a file? It only allows for a link not actual file.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
16 | |
15 | |
7 | |
7 |
User | Count |
---|---|
37 | |
31 | |
16 | |
16 | |
12 |