cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Diego-mx Regular Visitor
Regular Visitor

Boolean calculations and filters

I've seen boolean calculations using filters like this: 

trues_count = CALCULATE( COUNT([Element A]),
    FILTER(Table, [Element A] = "True"))

Since I'm using more filters I need more control on those counts, which could resemble otther languages that treat TRUE as 1 and FALSE as 0. 
For example,

A5_proportion = CALCULATE( AVERAGE(Table[indicator A] <= 5), 
    Table[Filter B], 
    TREATAS( VALUES(Calendar[date] ), Table[event_date])
)


This isn't possible because AVERAGE requires a column.  
Does anyone know a good way to achieve this?  Thanks. 

2 REPLIES 2
OwenAuger Super Contributor
Super Contributor

Re: Boolean calculations and filters

@Diego-mx

If you want to average an expression evaluated over each row of a table, you can use the iterator AVERAGEX.

Also, in DAX, booleans are not automatically cast as numbers, but you can multiply by 1 or add 0 to achieve the same effect.

 

An expression which I think achieves what you want, in place of AVERAGE(Table[indicator A] <= 5), is

AVERAGEX ( Table, ( Table[indicator A] <= 5 ) + 0 )

Regards,

Owen



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

Proud to be a Datanaut!




Diego-mx Regular Visitor
Regular Visitor

Re: Boolean calculations and filters

 

Thanks for this hint.  
I shall mark this as a solution. 

Still, I'm missing how to combine regular filters with virtual ones from TREATAS. 

I'll post a new message. 

Cheers. 

 

Helpful resources

Announcements
Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Summit North America

Power Platform Summit North America

Register by September 5 to save $200

Virtual Launch Event

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Users Online
Currently online: 307 members 2,742 guests
Please welcome our newest community members: