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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Convert True False and Count - DAX Help

I have a column in a dataset which is either True or False.  The data speaks to a specific action taken within our business.  I attempted to create an IF statement that reads:

 

If(Table]="False", "Incomplete","Complete")

 

I receive a message  that reads "DAX comparison operations do not support comparing values of type True/False with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values."

 

A workaround would be to copy the column and replace the values, but that seems hacky and so I am looking for something more elegant.

 

Ultimately I need to count "Completes".

 

Questions to be answered:

1.  What is the best way to convert the True/False so that I can use an IF statement(or something like it)?

2.  How can I get a total count of only the rows marked complete?

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous,

 

1. Since your column is a state type you need to use the FALSE() / TRUE() formulas and not the text "FALSE"/"TRUE" so in this case you would use something like this:

Completed = IF(Table[Status]=FALSE(), "Incomplete","Complete")

2. You have several ways of doing this:

       a) Add the Completed column previously calculated on a visual and then select in the filter the status you need to count.

       b) Add the following measure be aware that this is a hard coded filter so if you need to change any filter on this you have to             rewrite your measure however no need to have :

Count_completed_ = CALCULATE(COUNT('Table'[Completed]),'Table'[Completed]="Complete")

      c) Add the following measure to your model, but if you only want to get one of the values you need to put in place the visual     filter as it's done in the a), this is a more dinamic measure since you can have several states in your visual if you use the b)      option you will be restricted to one state. (as you can see below this measure allow you to use more than one value at a time.

Count_Complete =
VAR count_status =
    COUNT ( 'Table'[Completed] )
RETURN
    CALCULATE ( count_status, 'Table'[Completed] = VALUES ( 'Table'[Completed] ) )

Below are the examples for each of the options:

 

status.png

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi @Anonymous,

 

1. Since your column is a state type you need to use the FALSE() / TRUE() formulas and not the text "FALSE"/"TRUE" so in this case you would use something like this:

Completed = IF(Table[Status]=FALSE(), "Incomplete","Complete")

2. You have several ways of doing this:

       a) Add the Completed column previously calculated on a visual and then select in the filter the status you need to count.

       b) Add the following measure be aware that this is a hard coded filter so if you need to change any filter on this you have to             rewrite your measure however no need to have :

Count_completed_ = CALCULATE(COUNT('Table'[Completed]),'Table'[Completed]="Complete")

      c) Add the following measure to your model, but if you only want to get one of the values you need to put in place the visual     filter as it's done in the a), this is a more dinamic measure since you can have several states in your visual if you use the b)      option you will be restricted to one state. (as you can see below this measure allow you to use more than one value at a time.

Count_Complete =
VAR count_status =
    COUNT ( 'Table'[Completed] )
RETURN
    CALCULATE ( count_status, 'Table'[Completed] = VALUES ( 'Table'[Completed] ) )

Below are the examples for each of the options:

 

status.png

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Thanks @MFelix !

 

This is awesome.  These answers are what makes the community so positive.  Really appreciate it.

 

One last question...

 

Is there a way to conditionally format the value of Complete and Incomplete i.e. Green / Red Text?

 

Thanks.

Hi @Anonymous, 

 

The conditional formating is only possible in numbers, not with text you can use this other reply I used for another similar question.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



I would love to see a less processor-intensive way to do this calc.  

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.