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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare 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
Impactful Individual
Impactful Individual

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
Impactful Individual
Impactful Individual

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
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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

October NL Carousel

Fabric Community Update - October 2024

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