Forum Discussion
Nested IF
- 9 months ago
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"
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"