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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
bryanc78
Helper IV
Helper IV

Need help conveting Excel formula to Power Query (if statement and search/filter)

Greetings everyone.

 

Hoping I could get help converting an excel formula to M

 

I have a dataset that gives me a list of options.  I need to be able to tell what options are missing (the list of options will never change)

 

For example, I have a column called Apples.  This column will either list NA, Empty or a selection of apples.   If it's NA, then return NA.  If Empty, then return Empty.  If all the types of apples are listed, then return Full.  If some of the apples are missing, then return what's missing

 

bryanc78_0-1649437020466.png

 

Hope this example explains what I'm looking for

1 ACCEPTED SOLUTION
mussaenda
Super User
Super User

Hi @bryanc78 ,

 

If you wanted in power query,

try this:

if List.Count(Text.PositionOf(Text.Upper([Apples]),"APPLES",Occurrence.All )) >1
then "Full"
else

if Text.Contains(
    Text.Upper([Apples]), "RED")
then "Not Full - Missing Green Apples"
else 

if Text.Contains(
    Text.Upper([Apples]), "GREEN")
then "Not Full - Missing Red Apples"
else 

if Text.Contains(
    Text.Upper([Apples]), "EMPTY") 
    then "Empty"
    else  

if Text.Contains(
    Text.Upper([Apples]), "N") 
    and Text.Contains(
    Text.Upper([Apples]), "A")
    then "NA"
    else 

null

 

I also attached a sample pbix for your reference.

 

Hope this helps

View solution in original post

2 REPLIES 2
mussaenda
Super User
Super User

Hi @bryanc78 ,

 

If you wanted in power query,

try this:

if List.Count(Text.PositionOf(Text.Upper([Apples]),"APPLES",Occurrence.All )) >1
then "Full"
else

if Text.Contains(
    Text.Upper([Apples]), "RED")
then "Not Full - Missing Green Apples"
else 

if Text.Contains(
    Text.Upper([Apples]), "GREEN")
then "Not Full - Missing Red Apples"
else 

if Text.Contains(
    Text.Upper([Apples]), "EMPTY") 
    then "Empty"
    else  

if Text.Contains(
    Text.Upper([Apples]), "N") 
    and Text.Contains(
    Text.Upper([Apples]), "A")
    then "NA"
    else 

null

 

I also attached a sample pbix for your reference.

 

Hope this helps

Vijay_A_Verma
Super User
Super User

Use this in a custom column

if [Apples]="[N/A]" then "N/A"
else if [Apples]="[Empty]" then "Empty"
else if Text.Contains([Apples],"Green Apples") and Text.Contains([Apples],"Red Apples") then "Full"
else if Text.Contains([Apples],"Green Apples") then "Not Full - Missing Red Apples"
else if Text.Contains([Apples],"Red Apples") then "Not Full - Missing Green Apples"
else null

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors