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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Fighting21
Frequent Visitor

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
suparnababu8
Super User
Super User

Hi @Fighting21 

 

1st create calculated column that computes the difference for each row

CurrentDateValueMPreviousDateValue = 
VAR CurrentDate = '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
    )
RETURN
    CurrentDateValue - PreviousDateValue

 Then create a measure to count the rows where the calculated column is less than 0

 

CountlessthazeroValues = 
CALCULATE(
    COUNTROWS('DataTable'),
    FILTER(
        'DataTable',
        'DataTable'[CurrentDateValueMPreviousDateValue] < 0
    )
)

 

Let me know if it works

View solution in original post

2 REPLIES 2
suparnababu8
Super User
Super User

Hi @Fighting21 

 

1st create calculated column that computes the difference for each row

CurrentDateValueMPreviousDateValue = 
VAR CurrentDate = '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
    )
RETURN
    CurrentDateValue - PreviousDateValue

 Then create a measure to count the rows where the calculated column is less than 0

 

CountlessthazeroValues = 
CALCULATE(
    COUNTROWS('DataTable'),
    FILTER(
        'DataTable',
        'DataTable'[CurrentDateValueMPreviousDateValue] < 0
    )
)

 

Let me know if it works

Ritaf1983
Super User
Super User

Hi @Fighting21 

Please provide a workable sample data and your expected result from that. It is hard to figure out what you want to achieve from the description alone.  

https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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