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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Solution Sage
Solution Sage

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
Solution Sage
Solution Sage

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.