cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
henriquemalone
Helper II
Helper II

How make IF returns value from column

Hello!


I'm newbie at Power BI and Im struggling to solve a simple question.

I did a search on forum but there is so much information and i didn't find what i need especifically.

 

So let's go.

My trouble is with the "IF"

 

What I need to do is

IF(ColumnA = 0, "nok", *return the value in ColumnA*)

 

For exemple

ColumnAColumn with IF
0nok
11
0nok
11

 

The columnA is a float type.

I tried:

IF('Table'[ColumnA] = 0, "nok", SUM('Table'[ColumnA]))

IF('Table'[ColumnA] = 0, "nok", ALL('Table'[ColumnA]))

IF('Table'[ColumnA] = 0, "nok", VALUE('Table'[ColumnA]))

...

but i got the error: 

Expressions that generate variable data types cannot be used to define calculated columns.

 

Anybody can help me, please? 😞 

1 ACCEPTED SOLUTION

Hi, @henriquemalone 

In my opinion, I think the error is because of the data type.

Please try to change the data type of DDL Pending QTY to TEXT, and try the below for creating a new column.

 

Coluna = IF('Base SAP'[DDL Pending Qty] = "0", "NOK", 'Base SAP'[DDL Pending Qty])
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

View solution in original post

10 REPLIES 10
Jihwan_Kim
Community Champion
Community Champion

Hi, @henriquemalone 

If you are trying to create a new column, please try the below.

 

new column = 

IF('Table'[ColumnA] = 0, "nok", 'Table'[ColumnA])

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

It didnt work 😞

i got the message:

Expressions that generate variable data types cannot be used to define calculated columns.

Hi, @henriquemalone 

Thank you for your feedback.

If it is OK with you, please share your sample pbix file's link here, then I can try to look into it to come up with a more accurate solution.

 

Thank you.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

Sure!

 

PBIX 

 

But you'll need some explanations.

I created a generic table to explain my issue.

 

On my pbix file, i have to do the IF with the column "DDL Pending Qty", so:

Column = IF('Base SAP'[DDL Pending Qty] = 0, "NOK", 'Base SAP'[DDL Pending Qty])

Hi, 

Thank you for your message.

I think you shared a link address of your PBI service website, which I cannot access.

 


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

Sorry 😞

 

How can i share my sample pbix file's link?

Sorry for this kind of question

Hi, @henriquemalone 

You can save your sample pbix file in OneDrive or GoogleDrive, and you can share the link here.

Thank you.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

Thank you

 

Heres the link:

 

https://drive.google.com/drive/folders/1HcMUlF0eddyPO6LA6XLgRR_mSwlsonSA?usp=sharing 

 

Note: The column "DDL Pending Qty" is from the file "Base SAP"

Hi, @henriquemalone 

In my opinion, I think the error is because of the data type.

Please try to change the data type of DDL Pending QTY to TEXT, and try the below for creating a new column.

 

Coluna = IF('Base SAP'[DDL Pending Qty] = "0", "NOK", 'Base SAP'[DDL Pending Qty])
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Best regards, JiHwan Kim

Linkedin: https://www.linkedin.com/in/jihwankim1975/

Twitter: https://twitter.com/Jihwan_JHKIM

View solution in original post

Oh, thank you very much!
It worked!
 
I tried this:
Coluna = IF(CONVERT('Base SAP'[DDL Pending Qty], STRING) = "0", "", CONVERT('Base SAP'[DDL Pending Qty], STRING))

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.