cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Super User II
Super User II

Convert boolean to scalar value?

This might be a simple question but it is eluding me, short of a longer measure (which I have already created), is there a single function to convert boolean field to a scalar value?

 

For example, MIN and MAX can be used to convert text and number fields to a scalar value, and FIRSTDATE and LASTDATE will do the same for a date field, but MIN/MAX cannot be use on boolean (TRUE/FALSE) columns.

 

Scanning through the DAX functions isn't revealing anything.

 

I don't need a measure to do this. I've already done that. I just wondered if there was a single function to do this like there is for text, numbers, and dates.


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

Proud to be a Super User!


MCSA: BI Reporting
1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft v-jayw-msft
Microsoft

Re: Convert boolean to scalar value?

Hi @edhans ,

 

You can use SELECTEDVALUE() function instead of MAX() function.

Last Date Is Validated = CALCULATE(SELECTEDVALUE('Table'[Validated] ),FILTER('Table',LASTDATE('Table'[Date])=DATE(2018,2,1)))

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
FrankAT Regular Visitor
Regular Visitor

Re: Convert boolean to scalar value?

Hi,

try:

TRUE() + 0 evaluates to 1
FALSE() + 0 evaluates to 0.
 
Regards FrankAT
Super User II
Super User II

Re: Convert boolean to scalar value?

Hi @FrankAT 

 

I have a table that looks like this:

DateValidated
1/1/2018True
2/1/2018False

 

If [Validated] was a text field, I could convert it to a scalar value by using the following measure:

 

Last Date Is Validated =
CALCULATE(
    MAX( TableName[Validated] ),
    LASTDATE( TableName[Date] )
        = DATE( 2018, 2, 1 )
)

 


That measure would evaluate to True() so I could do something else with that - an IF statement for example. MAX() converted the single record table for that field to a scalar value - or would if [Validated] was a numeric or alphanumeric field.

 

But MAX doesn't work on a boolean column, so that doesn't work. Trying to see if there is a single function that does work with boolean fields.


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

Proud to be a Super User!


MCSA: BI Reporting
freder1ck Member
Member

Re: Convert boolean to scalar value?

INT ( TRUE() )

 

Microsoft v-jayw-msft
Microsoft

Re: Convert boolean to scalar value?

Hi @edhans ,

 

You can use SELECTEDVALUE() function instead of MAX() function.

Last Date Is Validated = CALCULATE(SELECTEDVALUE('Table'[Validated] ),FILTER('Table',LASTDATE('Table'[Date])=DATE(2018,2,1)))

 

Best Regards,

Jay

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

Super User II
Super User II

Re: Convert boolean to scalar value?

Thank you Jay. SELECTEDVALUE() seems to be exactly what I was looking for in this instance.


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

Proud to be a Super User!


MCSA: BI Reporting

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors