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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply

Counting true and false across columns

Hiya,

 

I want to make a new column which calculates the number of 'trues' for each opportunity across a number of other columns.

 

The example data is below, but for some context 'service' fields are not dropdowns, they're set up as individuals checkboxes (Service_A, Service_B, Service_C) so are therefore separate columns showing true or false. However I know need to count the number of services in each opportunity. Please can someone help me?

 

Laura 

 

OppNameService_AService_BService_CCount of Services
Name1 True 1
Name2TrueTrue 2
Name3 TrueTrue2
Name4TrueTrueTrue3

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@LauraCawdronDav You could do this:

Measure =
  COUNTROWS(
    FILTER(
      UNION(
        SELECTCOLUMNS('Table',"Service",[Service_A]),
        SELECTCOLUMNS('Table',"Service",[Service_B]),
        SELECTCOLUMNS('Table',"Service",[Service_C])
      ),
     [Service] = TRUE()
   )
 )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
loveyouball
New Member

DAX is easy, CALCULATE makes DAX hard...

mangaus1111
Solution Sage
Solution Sage

Hi @LauraCawdronDav ,

 

try to substitute [Service] = TRUE() with [Service] = "TRUE"

 

Please hit the thumbs up & mark it as a solution if it helps you. Thanks.

 

mangaus1111
Solution Sage
Solution Sage

Hi @LauraCawdronDav ,

 

you can first unpivot your table in Power Query:

 

1) Original Table "Opportunity"

 

mangaus1111_0-1665414880301.png

 

2) Unpivoted Table "Opportunity"

 

mangaus1111_1-1665414958093.png

 

after that you can use this measure:

CountServices = COUNTROWS(Opportunity)

 

and get the below result:

 

mangaus1111_2-1665415159132.png

Please hit the thumbs up & mark it as a solution if it helps you. Thanks.

 

 

Hiya, I don't think I can unpivot my table as this is data taken directly from our CRM system and there are 60 other columns and fields I'm using elsewhere (and with different measures). Is there a way to do this without messing up the other measures I have? 

Thanks!

Laura 

Greg_Deckler
Super User
Super User

@LauraCawdronDav You could do this:

Measure =
  COUNTROWS(
    FILTER(
      UNION(
        SELECTCOLUMNS('Table',"Service",[Service_A]),
        SELECTCOLUMNS('Table',"Service",[Service_B]),
        SELECTCOLUMNS('Table',"Service",[Service_C])
      ),
     [Service] = TRUE()
   )
 )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

I've tried the measure but that seems to just tell me that there are services, rather than count the number of services which is more what i'm looking for. Is that right?

 

Laura

@LauraCawdronDav I have both the Measure and Column versions in the attached PBIX below signature. The Measure works as is, here is the column:

Column = 
    VAR __Opp = [OppName]
    VAR __Table = { [Service_A], [Service_B], [Service_C] }
RETURN
  COUNTROWS(
    FILTER(
     __Table,
     [Value] = TRUE()
   )
 )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@LauraCawdronDav If you put that measure in a table visual along with Opportunity, it should return the count of the number of services in each opportunity.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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