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

Nested if

Hi all,

 

I'm trying to nest several if conditions. This is the context:

- Column1 [S_LocalExpertDecision]: It is a string and can take several values or be null. I want this field if it isn't null. Otherwise:

- Column2 [InnovationLevel]: It is a number from 0 to 10, or null. I convert this value to text according a rule (<5 or >=5). If it is null, I will consider the next column.

- Column3 [PS_Decision]: It's similar to Column1. I just use this field if the previous one are null. Just in case this is null, the result will be null.

 

Taking this into account, I have this code:

 

= if [S_LocalExpertDecision] = null then
(if [InnovationLevel] = null then 
(if [PS_Decision] = null then null
else if Text.Contains([PS_Decision], "Innovation") then "Innovation"
else if Text.Contains([PS_Decision], "Continuous") then "Continuous Improvement"
else if Text.Contains([PS_Decision], "Dispose") then "Discarded"
else null)
else if [InnovationLevel] > 5 then "Innovation"
else if [InnovationLevel] <= 5 then "Continuous Improvement"
else null)
else if Text.Contains([S_LocalExpertDecision], "Innovation") then "Innovation"
else if Text.Contains([S_LocalExpertDecision], "Continuous") then "Continuous Improvement"
else if Text.Contains([S_LocalExpertDecision], "Dispose") then "Discarded"
else null

When I apply this, the column doesn't work and show lots of null entries. Any suggestion?

 

Thank you in advance.

 

Best regards,

 

Fernando

1 ACCEPTED SOLUTION

Accepted Solutions
gpoggi Regular Visitor
Regular Visitor

Re: Nested if

Hi @fernandocxv ,

 

I think you have a couple of extra nulls in your formula:

nullsproblem.pngextra nulls

 

 

 

 

 

 

 

 


With those nulls you won't see [PS_Decision] and [S_LocalExpertDecision] values when they doesn't meet your text criteria.

 

Try to run this code and let me know if you get any errors:

 

if
  [S_LocalExpertDecision] = null
then
  if
    [InnovationLevel] = null
  then
    if
      [PS_Decision] = null
    then
      null
    else
      if
        Text.Contains([PS_Decision], "Innovation")
      then
        "Innovation"
      else
        if
          Text.Contains([PS_Decision], "Continuous")
        then
          "Continuous Improvement"
        else
          if
            Text.Contains([PS_Decision], "Dispose")
          then
            "Discarded"
          else
	    [PS_Decision]
  else
    if
      [InnovationLevel] > 5
    then
      "Innovation"
    else
      "Continuous Improvement"
else
  if
    Text.Contains([S_LocalExpertDecision], "Innovation")
  then
    "Innovation"
  else
    if
      Text.Contains([S_LocalExpertDecision], "Continuous")
    then
      "Continuous Improvement"
    else
      if
        Text.Contains([S_LocalExpertDecision], "Dispose")
      then
        "Discarded"
      else
        [S_LocalExpertDecision]

Any question , please let me know.

 

Regards,

 

Gian Carlo Poggi

View solution in original post

2 REPLIES 2
gpoggi Regular Visitor
Regular Visitor

Re: Nested if

Hi @fernandocxv ,

 

I think you have a couple of extra nulls in your formula:

nullsproblem.pngextra nulls

 

 

 

 

 

 

 

 


With those nulls you won't see [PS_Decision] and [S_LocalExpertDecision] values when they doesn't meet your text criteria.

 

Try to run this code and let me know if you get any errors:

 

if
  [S_LocalExpertDecision] = null
then
  if
    [InnovationLevel] = null
  then
    if
      [PS_Decision] = null
    then
      null
    else
      if
        Text.Contains([PS_Decision], "Innovation")
      then
        "Innovation"
      else
        if
          Text.Contains([PS_Decision], "Continuous")
        then
          "Continuous Improvement"
        else
          if
            Text.Contains([PS_Decision], "Dispose")
          then
            "Discarded"
          else
	    [PS_Decision]
  else
    if
      [InnovationLevel] > 5
    then
      "Innovation"
    else
      "Continuous Improvement"
else
  if
    Text.Contains([S_LocalExpertDecision], "Innovation")
  then
    "Innovation"
  else
    if
      Text.Contains([S_LocalExpertDecision], "Continuous")
    then
      "Continuous Improvement"
    else
      if
        Text.Contains([S_LocalExpertDecision], "Dispose")
      then
        "Discarded"
      else
        [S_LocalExpertDecision]

Any question , please let me know.

 

Regards,

 

Gian Carlo Poggi

View solution in original post

Community Support Team
Community Support Team

Re: Nested if

Hi @fernandocxv ,

Have you solved the problem?

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

If you still need help, please share the data sample and your desired output so that we could help further on it.

Best Regards,

Cherry

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

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Top Kudoed Authors
Users Online
Currently online: 227 members 1,894 guests
Please welcome our newest community members: