cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

Question: Issues with Calculated Column Using IF or SWITCH Logic

Hi,

 

Fairly new to Power BI and I can't seem to find what I am doing wrong via Google or this forum. I am looking to create a calculated column on a table (Dataset) that selects a row value based on IF or SWITCH statement logic. I've tried both statement types but get the same result.

 

The IF statement I've been working on:

 

 

Compare Column = 
IF(
ISBLANK('Dataset'[Column1])==FALSE,
'Dataset'[Column1],
IF(ISBLANK('Dataset'[Column1])==TRUE,
'Dataset'[Column2],
IF(ISBLANK('Dataset'[Column1])==TRUE && ISBLANK('Dataset'[Column2])==TRUE,
'Dataset'[Column3], 
IF(ISBLANK('Dataset'[Column1])==TRUE && ISBLANK('Dataset'[Column2])==TRUE && ISBLANK('Dataset'[Column3])==TRUE,
'Dataset'[Column4],
""))))

 

 

The SWITCH statement I've been working on:

 

 

Compare Column = 
SWITCH(
TRUE(),
NOT(ISBLANK('Dataset'[Column1])),
'Dataset'[Column1],
ISBLANK('Dataset'[Column1]),
'Dataset'[Column2],
ISBLANK('Dataset'[Column1]) && ISBLANK('Dataset'[Column2]),
'Dataset'[Column3], 
ISBLANK('Dataset'[Column1]) && ISBLANK('Dataset'[Column2]) && ISBLANK('Dataset'[Column3]),
'Dataset'[Column4],
"")

 

 

 

Once Column1 is blank, the calculated column (Compare Column) row value returns as blank.

For example, this is how my current calculated column returns:

KeyColumn1Column2Column3Column4Compare Column
1234ABCDA
1235 BCD 
1236  CD 
1237   D 
1238     

 

What I am wanting to achieve:

KeyColumn1Column2Column3Column4Compare Column
1234ABCDA
1235 BCDB
1236  CDC
1237   DD
1238     

 

What am I doing wrong here...?

 

Thanks,

Lejaregg

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Question: Issues with Calculated Column Using IF or SWITCH Logic

@Lejaregg ,

 

Try reversing the Switch Values;

 

Compare Column = 
SWITCH(
TRUE(),
ISBLANK('Dataset'[Column1]) && ISBLANK('Dataset'[Column2]) && ISBLANK('Dataset'[Column3]),
'Dataset'[Column4],
ISBLANK('Dataset'[Column1]) && ISBLANK('Dataset'[Column2]),
'Dataset'[Column3],
ISBLANK('Dataset'[Column1]),
'Dataset'[Column2],
NOT(ISBLANK('Dataset'[Column1])),
'Dataset'[Column1],
"")

.

 

Also, please share some sample data for us to check further.

 

Regards,

Harsh Nathani

 

 Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

View solution in original post

1 REPLY 1
Highlighted
Community Champion
Community Champion

Re: Question: Issues with Calculated Column Using IF or SWITCH Logic

@Lejaregg ,

 

Try reversing the Switch Values;

 

Compare Column = 
SWITCH(
TRUE(),
ISBLANK('Dataset'[Column1]) && ISBLANK('Dataset'[Column2]) && ISBLANK('Dataset'[Column3]),
'Dataset'[Column4],
ISBLANK('Dataset'[Column1]) && ISBLANK('Dataset'[Column2]),
'Dataset'[Column3],
ISBLANK('Dataset'[Column1]),
'Dataset'[Column2],
NOT(ISBLANK('Dataset'[Column1])),
'Dataset'[Column1],
"")

.

 

Also, please share some sample data for us to check further.

 

Regards,

Harsh Nathani

 

 Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!!

View solution in original post

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors