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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
adnankabina
Helper II
Helper II

how to use countif accross each columns

if there is number not 0 in clolumn it should count 1 from a to c as example below. If all columns values >0 then it should count 1.

I want that result at the end. In excel I used =3- Countif(a1:c1, "0")

 

 

A                 B                       C              RESULT

2.1             8.9                      6                 3

3.0              0                       0                  1

0                2.5                     8                 2

0                 0                       0                 0

2 ACCEPTED SOLUTIONS
ChrisMendoza
Resident Rockstar
Resident Rockstar

@adnankabina 

Measure = COUNTX ( FILTER ( TableName, TableName[A] > 0 ), TableName[A] )
        + COUNTX ( FILTER ( TableName, TableName[B] > 0 ), TableName[B] )
        + COUNTX ( FILTER ( TableName, TableName[C] > 0 ), TableName[C] ) + 0





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

CNENFRNL
Community Champion
Community Champion

A more elegant solution in Power Query, especially there are more columns,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIzVNJRstCzBJJmQGwA5hkqxepEKxlD+SBsCsSWYFEQz0gPxLcAs4zAKmAyyBhoSiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t, D = _t, E = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Result", each List.Accumulate(Record.ToList(_),0,(s,c)=>if c<>"0" then s+1 else s))
in
    #"Added Custom"

Screenshot 2021-05-20 205634.png

 

BTW, here's a concise Excel formula,

Untitled.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

6 REPLIES 6
adnankabina
Helper II
Helper II

Thanks everyone for helping me out, really appreciated. 😊

CNENFRNL
Community Champion
Community Champion

A more elegant solution in Power Query, especially there are more columns,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtIzVNJRstCzBJJmQGwA5hkqxepEKxlD+SBsCsSWYFEQz0gPxLcAs4zAKmAyyBhoSiwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t, D = _t, E = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Result", each List.Accumulate(Record.ToList(_),0,(s,c)=>if c<>"0" then s+1 else s))
in
    #"Added Custom"

Screenshot 2021-05-20 205634.png

 

BTW, here's a concise Excel formula,

Untitled.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

@CNENFRNL

where should I put this code in blank query? Can we make measure or add column in edit query ?

Hi @adnankabina !

You can place this in Power Query, new blank query. The DAX code which i provided can be using in New Column.

 

Regards,

Hasham

ChrisMendoza
Resident Rockstar
Resident Rockstar

@adnankabina 

Measure = COUNTX ( FILTER ( TableName, TableName[A] > 0 ), TableName[A] )
        + COUNTX ( FILTER ( TableName, TableName[B] > 0 ), TableName[B] )
        + COUNTX ( FILTER ( TableName, TableName[C] > 0 ), TableName[C] ) + 0





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



HashamNiaz
Solution Sage
Solution Sage

Hi @adnankabina !

You can using following DAX to create new column;

 

AllColumn = 
    VAR _Col1 = IF(Table[A] > 0, 1, 0)
    VAR _Col2 = IF(Table[B] > 0, 1, 0)
    VAR _Col3 = IF(Table[C] > 0, 1, 0)
RETURN
    _Col1 + _Col2 + _Col3


Hope this wil solve your issue.

 

Regards,

Hasham

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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