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
Pavanace16
Regular Visitor

Calculate the count of first consecutive negative values

Hi All,

I'm trying to find the count of the first consecutive negative values 
Screenshot 2022-11-04 210053.jpg

 

As you see in the image I've selected one ipn and we have projected on-hand values by date I need the count from 19 Dec 2022 to 23 Jan 2023 which is 6 and these are the first consecutive negative values for the projected on-hand.
Can anyone help me with this I need a measure/ calculated column to solve it?

1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

Hi @Pavanace16 ,

 

According to your description, here are my steps you can follow as a solution.

(1)This is my test data.

vtangjiemsft_0-1667815880769.png

(2)We can create  a calculated column.

 

Flag = 
MAXX (
    FILTER (
        'Table',
        'Table'[Date] <= EARLIER ('Table'[Date] )
            && 'Table'[Projected On Hand]> 0
    ),
    'Table'[Date]
)
rows = 
IF (
    'Table'[Projected On Hand] < 0,
    COUNTROWS( (
        FILTER (
            'Table',
            'Table'[Projected On Hand]<0
                && 'Table'[Flag]= EARLIER ( 'Table'[Flag] )
        )
    )
))

(3)We can create  a measure. 

Measure 2 =

var _a = MINX(FILTER('Table',[Projected On Hand]<0),[Date])

var _b = MINX(FILTER('Table',[Date]>_a&&[Projected On Hand]>=0),[Date])

return CALCULATE(COUNT('Table'[Date]),FILTER('Table',[Date]>=_a&&[Date]<_b))

 

(3) Then the result is as follows.

vtangjiemsft_0-1667870351912.png

Best Regards,

Neeko Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

 

 

View solution in original post

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

Hi @Pavanace16 ,

 

According to your description, here are my steps you can follow as a solution.

(1)This is my test data.

vtangjiemsft_0-1667815880769.png

(2)We can create  a calculated column.

 

Flag = 
MAXX (
    FILTER (
        'Table',
        'Table'[Date] <= EARLIER ('Table'[Date] )
            && 'Table'[Projected On Hand]> 0
    ),
    'Table'[Date]
)
rows = 
IF (
    'Table'[Projected On Hand] < 0,
    COUNTROWS( (
        FILTER (
            'Table',
            'Table'[Projected On Hand]<0
                && 'Table'[Flag]= EARLIER ( 'Table'[Flag] )
        )
    )
))

(3)We can create  a measure. 

Measure 2 =

var _a = MINX(FILTER('Table',[Projected On Hand]<0),[Date])

var _b = MINX(FILTER('Table',[Date]>_a&&[Projected On Hand]>=0),[Date])

return CALCULATE(COUNT('Table'[Date]),FILTER('Table',[Date]>=_a&&[Date]<_b))

 

(3) Then the result is as follows.

vtangjiemsft_0-1667870351912.png

Best Regards,

Neeko Tang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

 

 

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.