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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply

Nested IF

Need help adjusting formula to only be calculated when the Development Status is "Active-Dev" or "Active-Exe"

 

Original formula is: 

if [Interconnection Facilities ISD] <> null and

Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) >= 0 and

Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) <= 30 then

"Yes"

else

"No"

 

Proposed formula is:

If [Development Status] <> "Active – Dev" or "Active – Exe" then null

else

(

[Interconnection Facilities ISD] <> null and

Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) >= 0 and

Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) <= 30 then

"Yes"

else

"No"

)

 

receiving error in the 2nd "then" (italicized above)

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@rosamhernandez1 , Power query code 

= if [Development Status] <> "Active – Dev" and [Development Status] <> "Active – Exe" then
null
else
if [Interconnection Facilities ISD] <> null
and Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) >= 0
and Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) <= 30
then "Yes"
else "No"

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
Nabha-Ahmed
Super User
Super User

Hi @Zanqueta 

You need to check the Development Status first, and then run your original test block inside a nested if…then…else.

Correct M Code

if [Development Status] = "Active-Dev"
or [Development Status] = "Active-Exe" then
if [Interconnection Facilities ISD] <> null and
Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) >= 0 and
Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) <= 30 then
"Yes"
else
"No"
else
null


---

✔ Why your formula failed

Power Query M doesn’t allow else (condition then … else …)

The correct structure is always:


if … then
if … then … else …
else

Also A <> "X" or "Y" is invalid.
Must be written as:


A = "X" or A = "Y"

 

Zanqueta
Super User
Super User

Hi @rosamhernandez1,

 

The error happens because Power Query (M) does not allow a then statement inside parentheses without a complete if ... then ... else structure. Your proposed logic needs to be rewritten so that the condition for Development Status wraps the entire expression.
 
 

 

I suggest your adapt using this code:

if [Development Status] = "Active-Dev" or [Development Status] = "Active-Exe" then
    if [Interconnection Facilities ISD] <> null and
       Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) >= 0 and
       Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) <= 30 then
        "Yes"
    else
        "No"
else
    null

 

If this response was helpful in any way, I’d gladly accept a 👍much like the joy of seeing a DAX measure work first time without needing another FILTER.

Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop 🌀.

 

If this response was helpful in any way, I’d gladly accept a kudo.
Please mark it as the correct solution. It helps other community members find their way faster.
Connect with me on LinkedIn

amitchandak
Super User
Super User

@rosamhernandez1 , Power query code 

= if [Development Status] <> "Active – Dev" and [Development Status] <> "Active – Exe" then
null
else
if [Interconnection Facilities ISD] <> null
and Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) >= 0
and Duration.Days([Projected In Service Date] - [Interconnection Facilities ISD]) <= 30
then "Yes"
else "No"

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.