cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
danasdesk
Regular Visitor

Help with PowerQuery syntax using "if" and "and"

Good morning, other threads didn't help me with my syntax which is throwing an "Error".  I'm creating a custom column in PowerQuery.

 

=if ([Part Type]="TC" and [Part Size]<7) then 2

     else if ([Part Type]="TC" and [Part Size]>13.38) then 2

       else if ([Part Type]="LC" and [Part Size]<7) then 2

          else if ([Part Type]="LC" and [Part Size]>13.38) then 2

             else 0

 

I have two part types, LC and TC.  I have six sizes.  If the size is less than 7 or more than 13.38 i want a returned value of 2. if the size is in between 7 and 13.38 I want a returned value of 0.  I used multiple lines for clarity here but the formula is just ran as a sentence in the Custom Column Formula box.

 

 

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

Hi @danasdesk,

 

You can add a custom column with following formula:

#"Added Custom" = Table.AddColumn(#"Previous Step", "Custom", each if [Part Size]>=7 and [Part Size]<=13.38 then 0 else if [Part Type]="TC" or [Part Type]="LC" then 2 else 0)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @danasdesk,

 

You can add a custom column with following formula:

#"Added Custom" = Table.AddColumn(#"Previous Step", "Custom", each if [Part Size]>=7 and [Part Size]<=13.38 then 0 else if [Part Type]="TC" or [Part Type]="LC" then 2 else 0)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
LivioLanzo
Solution Sage
Solution Sage

Hi @danasdesk

 

what is the error?

 

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Actually, your question helped me think through why is it an error. My size was data typed as text, not a number.  Thank you!

My column just says "Error".  Any part number that is not TC and LC returns zero but any part number that is TC or LC returns "Error", regardless of size.  Thanks for taking a look...I thought my logic was okay but I'm missing something.

Helpful resources

Announcements
May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through June10th!

Power BI Dev Camp Session 22 without aka link and time 768x460.jpg

Check it Out!

Watch Session 22 Ted's Dev Camp along with past sessions!

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!

Top Kudoed Authors