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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
CoreyP
Solution Sage
Solution Sage

M Query Editor - Trouble with Conditional IF statement

Hey guys,

 

I have a dataset that is a transaction log of pallet movements within a warehouse. It has the following fields: Date, Pallet No., From Location, To Location. I am adding a conditional column to the dataset to identify what activity was taking place. Rules set on From Location and To Location determine the activity. All of my rules are working correctly except for one, and I can't figure out why. I'm hoping extra sets of eyes might see something I'm missing. 

 

Here is my entire column code: 

 

if 
[FROM_LOCATION] = "SPRCV"
and [TO_LOCATION] <> "SG-PRO-CESS"
and [TO_LOCATION] <> "OS-PUT-AWAY"
and [TO_LOCATION] <> "PUT-AWA-50"
then "Data Entry"
else


if 
[FROM_LOCATION] = "SPRCV"
and [TO_LOCATION] = "OS-PUT-AWAY" 
then "OS Dimming"
else


if 
[FROM_LOCATION] = "SG-PRO-CESS"
then "SG Data Entry"
else

if 
[FROM_LOCATION] = "DANGR-GOODS" 
or [TO_LOCATION] = "PUT-AWA-50"
then "Complex Data Entry"
else


if 
[FROM_LOCATION] = "PUT-AWA-40"
then "Declarations"
else


if 
[TO_LOCATION] = "REPCK-ENTRY"
then "Repack"
else


if 
Text.StartsWith([TO_LOCATION] , "A0")
or Text.StartsWith([TO_LOCATION] , "B0") 
then "Putaway" 
else


if 
[TO_LOCATION] = "PICK-ED1"
then "Loose Pick"
else


if 
[TO_LOCATION] = "SM-CON-SOL"
or [TO_LOCATION] = "NZ-CON-SOL"
then "Complex Pick"
else 

if 
Text.StartsWith([FROM_LOCATION], "REP")
and Text.StartsWith([TO_LOCATION], "PAS")
or Text.StartsWith([TO_LOCATION], "PUT")
then "Repack Entry"

else
"Other"

 

 

The specific activity I'm having trouble with is Repack Entry:

 

if 
Text.StartsWith([FROM_LOCATION], "REP")
and Text.StartsWith([TO_LOCATION], "PAS")
or Text.StartsWith([TO_LOCATION], "PUT")
then "Repack Entry"

else

 

The logic should read: If From Location starts with REP and To Location starts with PAS or PUT, then Repack Entry. 

The From Location beginning with REP should return only two values, REPCK-ENTRY and REP-ACK-ING ( If From Location equals REPCK-ENTRY or REP-ACK-ING and To Location starts with PAS or PUT, then Repack Entry ), however, when I validate I'm getting a lot of values in From Location that do not start with REP. 

 

Does anyone have any thoughts? 

Any help is MUCHO appreciated!

Thanks!

 

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @CoreyP ,

 

"The logic should read: If From Location starts with REP and To Location starts with PAS or PUT, then Repack Entry. "

Try this code:

if 
        Text.StartsWith([FROM_LOCATION], "REP") 
        and 
        (
        Text.StartsWith([TO_LOCATION], "PAS")
        or Text.StartsWith([TO_LOCATION], "PUT")
        )
        then "Repack Entry" else null)

bb2.PNG

 

Best regards,
Lionel Chen

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

2 REPLIES 2
v-lionel-msft
Community Support
Community Support

Hi @CoreyP ,

 

"The logic should read: If From Location starts with REP and To Location starts with PAS or PUT, then Repack Entry. "

Try this code:

if 
        Text.StartsWith([FROM_LOCATION], "REP") 
        and 
        (
        Text.StartsWith([TO_LOCATION], "PAS")
        or Text.StartsWith([TO_LOCATION], "PUT")
        )
        then "Repack Entry" else null)

bb2.PNG

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

MartynRamsden
Solution Sage
Solution Sage

Hi @CoreyP 

 

Looks like your 'Repack' IF statement is simply missing a set of parentheses.

Try this:

if 
Text.StartsWith([FROM_LOCATION], "REP")
and (Text.StartsWith([TO_LOCATION], "PAS")
or Text.StartsWith([TO_LOCATION], "PUT"))
then "Repack Entry"

else

 

Best regards,

Martyn

 

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.