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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SYChan_22
New Member

Count rows if more than 0.00 for multiple rows (considering different columns)

Hi Team, I am new to Power BI. I am currently looking for a solution on DAX measure. I would like to count the rows if the column Far (Left) OR Far (right) is more than 0.00 OR the column Near (Left) OR Near (right) is more than 0.00. See attached screenshot. The desired results that fit the condition would be 5, if count manually. I have tried several other formulas but it never work. Desperately looking for solution here. Thanks in advance. Cheers!

 

PowerBI.PNG

1 ACCEPTED SOLUTION

@SYChan_22  show the index in the matrix and use this as a measure

 

Measure = 
COUNTROWS (
    FILTER (
        
            tbl,
            
        ABS(CONVERT ( tbl[Prescription: Far left], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Far right], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Near left], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Near right], DOUBLE )) > 0
    )
)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

18 REPLIES 18
SYChan_22
New Member

Hi @smpa01 , thanks for your suggestion. I tried and it did not work ;( Is there any way to share the sample data here? I could not find any option to attach a file here. Thanks in advance for your help!

@SYChan_22  you can share it through google drive / 1 drive

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@SYChan_22 

Measure =
COUNTROWS (
    FILTER (
        SUMMARIZE (
            tbl,
            tbl[Prescription: Far left],
            tbl[Prescription: Far right],
            tbl[Prescription: Near left],
            tbl[Prescription: Near right]
        ),
        CONVERT ( tbl[Prescription: Far left], DOUBLE ) > 0
            || CONVERT ( tbl[Prescription: Far right], DOUBLE ) > 0
            || CONVERT ( tbl[Prescription: Near left], DOUBLE ) > 0
            || CONVERT ( tbl[Prescription: Near right], DOUBLE ) > 0
    )
)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

That works perfectly, @smpa01 and the solution saves me a lot of time!

 

Probably last question from my side: What if I would like to count the rows if it more than 0 and less than 0? In other words, if all the rows contain zero, it shoud not be counted. Thanks!

@SYChan_22  

In other words, if all the rows contain zero, it shoud not be counted - currently the code is doing that.

 

With the following

        CONVERT ( tbl[Prescription: Far left], DOUBLE ) > 0
            || CONVERT ( tbl[Prescription: Far right], DOUBLE ) > 0
            || CONVERT ( tbl[Prescription: Near left], DOUBLE ) > 0
            || CONVERT ( tbl[Prescription: Near right], DOUBLE ) > 0

 the code can't return any rows that will have column1=0 and column2=0 and column3=0 and column4=0.

 

Because DAX is explicitly asked to perform a serach and return a table where any of these 4 columns are >0, therfore the opposite can't be true.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Thanks @smpa01 for your clarification. But I realized the following was not displayed in the result (see screenshot). I would like the rows to be counted as well if it has negative value (or less than zero). Is there anything we can tweak on the DAX measure?

 

PBI 1.PNG

@SYChan_22  weap in ABS

Measure = 
COUNTROWS (
    FILTER (
        SUMMARIZE (
            tbl,
            tbl[Prescription: Far left],
            tbl[Prescription: Far right],
            tbl[Prescription: Near left],
            tbl[Prescription: Near right]
        ),
        ABS(CONVERT ( tbl[Prescription: Far left], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Far right], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Near left], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Near right], DOUBLE )) > 0
    )
)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Dear @smpa01, I performed the DAX measure. It works fine but it does not match the final results that I imagine. I realized the rows that has repetitions are not included. I would like to count the rows, even if it repeats (see screenshot). Any idea how to modify the DAX measure? Thanks a lot.

 

PBI 2.PNG

@SYChan_22  add an index column in the data and then run the measure

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01 , as suggested, I performed the following steps: Transform Data -> Add column -> Index column (From 1) -> Close and apply -> Add new measure -> Paste in the DAX. However, 0.00 appeared in the table and counted as 1 row. Have I missed out some steps here? Maybe you can help me on this? Appreciate for your further advice. Cheers

 

PBI_Index.PNG

@SYChan_22  show the index in the matrix and use this as a measure

 

Measure = 
COUNTROWS (
    FILTER (
        
            tbl,
            
        ABS(CONVERT ( tbl[Prescription: Far left], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Far right], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Near left], DOUBLE )) > 0
            || ABS(CONVERT ( tbl[Prescription: Near right], DOUBLE )) > 0
    )
)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01 , thanks for the valuable tips. The row that contains 0.00 isn't shown in the table anymore. As a final step, I would like to now count the rows in the index column in the matrix. How could we achieve this?

 

PBI 4.PNG

@SYChan_22  I think the quetion is getting sidetracked now and you are asking me different quetion. Did I manage to give you the answer to your original question? I like to think yes and please accept the answer and create a new question.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01, referring to my original question, I would like to count the rows that meet the abovementioned conditions (yes, the solution worked!). Ultimately, I would like to show the total number of rows that met the conditions in the card visual instead of showing them in the matrix. Sorry for the misunderstanding and I hope I expressed it clear enough now. 

@SYChan_22  did you actually really try putting the same measure in a card to see whether it works?

smpa01_0-1636048927724.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hi @smpa01 , the DAX (screenshot) in your previous message was not displayed the first time I read your message. Must be due to the weak internet connection here. Greetings from Kinshasa. Thanks for your expertise! 

smpa01
Super User
Super User

@SYChan_22  try this

 

MEASURE= COUNTROWS(FILTER(SUMMARIZE(tbl,tbl[Far(left)],tbl[Far(right)],tbl[Near(left)],tbl[Near(right)]),                       tbl[Far(left)]>0||tbl[Far(right)]>0||tbl[Near(left)]>0||tbl[Near(right)]>0))
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.