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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Fighting21
Frequent Visitor

How to count rows if my measure value is minus ?

+ I edited question

 

How can i count rows if my measure value <0
 

I made measure _CurrentDataValueMPreviousDateValue

 

_CurrentDateValueMPreviousDateValue =
VAR CurrentDate = MAX('DataTable'[Date])

VAR PreviousDate =
    CALCULATE(
        MAX('DataTable'[Date]),
        FILTER(
            ALL('DataTable'),
            'DataTable'[Date] < CurrentDate
        )
    )
VAR _CurrentDateValue =
CALCULATE(
    SUM('DataTable'[Value]),
    'DataTable'[Date] = CurrentDate
)

VAR _PreviousDateValue =
CALCULATE(
    SUM('DataTable'[Value]),
    'DataTable'[Date] = PreviousDate
)
VAR _CurrentDateValueMPreviousDateValue = _CurrentDateValue-_PreviousDateValue

RETURN
_CurrentDateValueMPreviousDateValue

 

and i try to count rows that _CurrentDataValueMPreviousDateValue is minus

 

so i tried 

Count = Countrows(filter('DataTable',[_CurrentDateValueMPreviousDateValue]<0))
 
but it's not work result is blank,
 
how can i count rows if measure value < 0 ?
 
I posted my example pbix file to could download is https://blog.naver.com/thstjdtn21/223637964699  
Count.png
1 ACCEPTED SOLUTION
shafiz_p
Super User
Super User

Hi @Fighting21  

 

You raw data don't have negative and after summarization, measure have negative. So, I think you need to summarize first and then compare with measure and count rows.

 

You can try the below code, if it is meets your goal:

 

CountNegetive = 
VAR SummarizedTable = 
SUMMARIZE(
    'DataTable',
    'DataTable'[Category],
    'DataTable'[SubCategory],
    'DataTable'[Date],
    "TotalValue", SUM('DataTable'[Value])
)

VAR CountNegativeRows = 

SUMX(
    SummarizedTable,
    IF(
        [_CurrentDateValueMPreviousDateValue] < 0,
        1,
        0
    )
)

RETURN

CountNegativeRows

 

 

I found this result, though I don't know it is the desired result what you want to achieve or not:

shafiz_p_0-1730182431371.png

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,
Shahariar Hafiz

View solution in original post

6 REPLIES 6
shafiz_p
Super User
Super User

Hi @Fighting21  

 

You raw data don't have negative and after summarization, measure have negative. So, I think you need to summarize first and then compare with measure and count rows.

 

You can try the below code, if it is meets your goal:

 

CountNegetive = 
VAR SummarizedTable = 
SUMMARIZE(
    'DataTable',
    'DataTable'[Category],
    'DataTable'[SubCategory],
    'DataTable'[Date],
    "TotalValue", SUM('DataTable'[Value])
)

VAR CountNegativeRows = 

SUMX(
    SummarizedTable,
    IF(
        [_CurrentDateValueMPreviousDateValue] < 0,
        1,
        0
    )
)

RETURN

CountNegativeRows

 

 

I found this result, though I don't know it is the desired result what you want to achieve or not:

shafiz_p_0-1730182431371.png

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,
Shahariar Hafiz

Thank you very much
Jihwan_Kim
Super User
Super User

Hi,

Please try something like below if it works.

expected result measure: =
VAR _t =
    FILTER ( DataTable, [_CurrentDataValueMPreviousDateValue] < 0 )
RETURN
    COUNTROWS ( _t )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Sorry, i changed my question.

MattAllington
Community Champion
Community Champion

You could write this

Countrows(filter(DataTable,Datatable[value]<0))


* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Sorry, i changed my question.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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