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
chel4782
Frequent Visitor

Need Help with Conditional Column in Power BI-Power Query

I have these two statements in excel, but when I try to do in Power Query I keep getting errors.

 

1. =IF(IF([@[PT/NPT]]="PT",IF([@activity]="NONOPS","",[@DURATION]),IF(OR([@operation]="saftey",[@operation]="commute",[@operation]="lunch"),[@DURATION],""))="",0,IF([@[PT/NPT]]="PT",IF([@activity]="NONOPS","",[@DURATION]),IF(OR([@operation]="saftey",[@operation]="commute",[@operation]="lunch"),[@DURATION],"")))

 

2.=IF(IF([@[PT/NPT]]="NPT",IF(OR([@operation]="WOV_SDFN",[@operation]="WTHR",[@operation]="COMMUTE",[@operation]="LUNCH",[@operation]="SAFETY",[@operation]="SFTY MTG",[@operation]="WTHR/WIND",[@operation]="SFTY_ NPT", [@operation]="WOV_TRAV"),"",[@DURATION]),"")="",0,IF([@[PT/NPT]]="NPT",IF(OR([@operation]="WOV_SDFN",[@operation]="WTHR",[@operation]="COMMUTE",[@operation]="LUNCH",[@operation]="SAFETY",[@operation]="SFTY MTG",[@operation]="WTHR/WIND",[@operation]="SFTY_ NPT", [@operation]="WOV_TRAV"),"",[@DURATION]),""))

2 ACCEPTED SOLUTIONS
v-juanli-msft
Community Support
Community Support

Hi @chel4782 

Formula1:

Power query

Creat two columns

Capture7.JPGCapture8.JPG

Custom=
if [#"PT/NPT"] = "PT" 
  then 
     if [activity] = "NONOPS" then " " else [DURATION]       else 
     if [operation] = "saftey" or [operation] = "commute" or [operation] = "lunch" 
       then [DURATION] else " "

 

Dax in a calcualted column

b =
IF (
    IF (
        [PT/NPT] = "PT",
        IF (
            [activity] = "NONOPS",
            "",
            [DURATION]
        ),
        IF (
            [operation] = "saftey"
                || [operation] = "commute"
                || [operation] = "lunch",
            [DURATION],
            ""
        )
    ) = "",
    0,
    IF (
        [PT/NPT] = "PT",
        IF (
            [activity] = "NONOPS",
            "",
            [DURATION]
        ),
        IF (
            [operation] = "saftey"
                || [operation] = "commute"
                || [operation] = "lunch",
            [DURATION],
            ""
        )
    )
)

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

This one worked

if[activity]="NONOPS" and [#"PT/NPT"]="PT" then "0"
else if ([operation]="safety" or [operation]="commute" or [operation]="lunch") then [DURATION] else [DURATION]

View solution in original post

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @chel4782 

Formula1:

Power query

Creat two columns

Capture7.JPGCapture8.JPG

Custom=
if [#"PT/NPT"] = "PT" 
  then 
     if [activity] = "NONOPS" then " " else [DURATION]       else 
     if [operation] = "saftey" or [operation] = "commute" or [operation] = "lunch" 
       then [DURATION] else " "

 

Dax in a calcualted column

b =
IF (
    IF (
        [PT/NPT] = "PT",
        IF (
            [activity] = "NONOPS",
            "",
            [DURATION]
        ),
        IF (
            [operation] = "saftey"
                || [operation] = "commute"
                || [operation] = "lunch",
            [DURATION],
            ""
        )
    ) = "",
    0,
    IF (
        [PT/NPT] = "PT",
        IF (
            [activity] = "NONOPS",
            "",
            [DURATION]
        ),
        IF (
            [operation] = "saftey"
                || [operation] = "commute"
                || [operation] = "lunch",
            [DURATION],
            ""
        )
    )
)

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This one worked too!  Thank you for your help!

SteveCampbell
Memorable Member
Memorable Member

the syntax in Power Query is

 

if [CONDITION] then {A} else if [CONDITION 2] then {B} else {C}

 

to use OR statement, use a little case or / and between conditions

 

if [CONDITION1] or [CONDITION2] then {A} else {B}

if [CONDITION1] and [CONDITION2] then {A} else {B}

 

Alternatively, you can add a conditional column 



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



This one worked

if[activity]="NONOPS" and [#"PT/NPT"]="PT" then "0"
else if ([operation]="safety" or [operation]="commute" or [operation]="lunch") then [DURATION] else [DURATION]

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.