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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
SelviPrabhu
Helper II
Helper II

Highlight 7th data point based on consecutive increases or decreases in line chart in PowerBI

Hi There,

I've Batch table where I'm having Batch ID and Total Orders and the data format will looks like as given in table below:

Batch Table:

BatchIDTotalOrders
10001100
1000290
1000380
1000470
1000560
1000640
1000720
10008101
10009200
10010100
10011200
100122
10013226
10014555
10015555
10016959
10017666
10018845
10019212
1002021

 

In Line Chart = X axis = Batch ID , Y Axis = Total Orders.

Now I need to highlight the 7th data point (7th batch id) only if there is 7  consecutive/continuous increases or decreases in the data point. In the image below , you can see first 7 data points are consecutively decreasing , now I need to highlight that 7 th data point alone. 

SelviPrabhu_0-1730178685968.png

I've tried  creating Measures but measures for ConsecutiveDecrease / ConsecutiveIncrease always returns 0 where as Expected value for ConsecutiveDecrease measure for 7th point is 1.

 

ConsecutiveDecrease =
VAR CurrentID = MAX('Batch Table'[BatchID])
VAR PreviousValues =
    FILTER(
        'Batch Table',
        'Batch Table'[BatchID] <= CurrentID && 'Batch Table'[BatchID] > CurrentID - 7
    )
VAR DecreaseCount =
    COUNTROWS(
        FILTER(
            PreviousValues,
            'Batch Table'[TotalOrders] <
            CALCULATE(
                MAX('Batch Table'[TotalOrders]),
                FILTER('Batch Table', 'Batch Table'[BatchID] = EARLIER('Batch Table'[BatchID]) +1)
            )
        )
    )
RETURN
    IF(DecreaseCount = 6, 1, 0)
 
ConsecutiveIncrease =
VAR CurrentID = MAX('Batch Table'[BatchID])
VAR PreviousValues =
    FILTER(
        'Batch Table',
        'Batch Table'[BatchID] <= CurrentID && 'Batch Table'[BatchID] > CurrentID - 7
    )
VAR IncreaseCount =
    COUNTROWS(
        FILTER(
            PreviousValues,
            'Batch Table'[TotalOrders] >
            CALCULATE(
                MAX('Batch Table'[TotalOrders]),
                FILTER('Batch Table', 'Batch Table'[BatchID] = EARLIER('Batch Table'[BatchID]) +1)
            )
        )
    )
RETURN
    IF(IncreaseCount = 6, 1, 0)
 
HighlightPoint =
IF(
   [ConsecutiveIncrease]=1 ||  [ConsecutiveDecrease] = 1,
   1,
   0
)
 
Pls. help on deriving the solution / solving this issue. Thanks in Advance!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

Thanks for the solution @rajendraongole1  offered,and i want to offer some more infotmation for user to refer to.

hello @SelviPrabhu , you can refer to the following sample.

Sample data 

vxinruzhumsft_0-1730258169142.png

Create the following measures.

_Decreasing =
VAR a =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [BatchID] = MAX ( [BatchID] ) - 1 ),
        [TotalOrders]
    )
VAR b =
    IF ( a <> BLANK (), a - SUM ( 'Table'[TotalOrders] ) )
VAR c =
    MINX ( ALLSELECTED ( 'Table' ), [BatchID] )
RETURN
    IF ( b > 0 || MAX ( 'Table'[BatchID] ) = c, 1, 0 )
_Increment =
VAR a =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [BatchID] = MAX ( [BatchID] ) - 1 ),
        [TotalOrders]
    )
VAR b =
    IF ( a <> BLANK (), SUM ( 'Table'[TotalOrders] ) - a )
VAR c =
    MINX ( ALLSELECTED ( 'Table' ), [BatchID] )
RETURN
    IF ( b > 0 || MAX ( 'Table'[BatchID] ) = c, 1, 0 )
Decreasing_flag =
VAR a =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [BatchID] <= MAX ( 'Table'[BatchID] )
                && [_Decreasing] = 0
        ),
        [BatchID]
    )
VAR b =
    IF (
        a = BLANK (),
        MAX ( 'Table'[BatchID] ) - MINX ( ALLSELECTED ( 'Table'[BatchID] ), [BatchID] ) + 1,
        MAX ( 'Table'[BatchID] ) - a + 1
    )
RETURN
    IF ( b <> 0 && MOD ( b, 7 ) = 0, 1, 0 )
increasing_flag =
VAR a =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [BatchID] <= MAX ( 'Table'[BatchID] )
                && [_Increment] = 0
        ),
        [BatchID]
    )
VAR b =
    IF (
        a = BLANK (),
        MAX ( 'Table'[BatchID] ) - MINX ( ALLSELECTED ( 'Table'[BatchID] ), [BatchID] ) + 1,
        MAX ( 'Table'[BatchID] ) - a + 1
    )
RETURN
    IF ( b <> 0 && MOD ( b, 7 ) = 0, 1, 0 )
Color_flag= IF([Decreasing_flag]=1||[increasing_flag]=1,1,0)

Then create a line chart visual first, and put the related field to the visual. and sort the visual ascending by BarchID, open the marker.

vxinruzhumsft_1-1730258427703.png

vxinruzhumsft_2-1730258472725.png

Then click the viusal, then change it to clustered column visual.

Then put the color_flag measure to the column color format.

vxinruzhumsft_3-1730258523692.png

 

vxinruzhumsft_4-1730258591940.png

 

Then click the visual , change it to line chart visual again.

Output

vxinruzhumsft_5-1730258814986.png

Best Regards!

Yolo Zhu

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

8 REPLIES 8
Anonymous
Not applicable

Hi,

Thanks for the solution @rajendraongole1  offered,and i want to offer some more infotmation for user to refer to.

hello @SelviPrabhu , you can refer to the following sample.

Sample data 

vxinruzhumsft_0-1730258169142.png

Create the following measures.

_Decreasing =
VAR a =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [BatchID] = MAX ( [BatchID] ) - 1 ),
        [TotalOrders]
    )
VAR b =
    IF ( a <> BLANK (), a - SUM ( 'Table'[TotalOrders] ) )
VAR c =
    MINX ( ALLSELECTED ( 'Table' ), [BatchID] )
RETURN
    IF ( b > 0 || MAX ( 'Table'[BatchID] ) = c, 1, 0 )
_Increment =
VAR a =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [BatchID] = MAX ( [BatchID] ) - 1 ),
        [TotalOrders]
    )
VAR b =
    IF ( a <> BLANK (), SUM ( 'Table'[TotalOrders] ) - a )
VAR c =
    MINX ( ALLSELECTED ( 'Table' ), [BatchID] )
RETURN
    IF ( b > 0 || MAX ( 'Table'[BatchID] ) = c, 1, 0 )
Decreasing_flag =
VAR a =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [BatchID] <= MAX ( 'Table'[BatchID] )
                && [_Decreasing] = 0
        ),
        [BatchID]
    )
VAR b =
    IF (
        a = BLANK (),
        MAX ( 'Table'[BatchID] ) - MINX ( ALLSELECTED ( 'Table'[BatchID] ), [BatchID] ) + 1,
        MAX ( 'Table'[BatchID] ) - a + 1
    )
RETURN
    IF ( b <> 0 && MOD ( b, 7 ) = 0, 1, 0 )
increasing_flag =
VAR a =
    MAXX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            [BatchID] <= MAX ( 'Table'[BatchID] )
                && [_Increment] = 0
        ),
        [BatchID]
    )
VAR b =
    IF (
        a = BLANK (),
        MAX ( 'Table'[BatchID] ) - MINX ( ALLSELECTED ( 'Table'[BatchID] ), [BatchID] ) + 1,
        MAX ( 'Table'[BatchID] ) - a + 1
    )
RETURN
    IF ( b <> 0 && MOD ( b, 7 ) = 0, 1, 0 )
Color_flag= IF([Decreasing_flag]=1||[increasing_flag]=1,1,0)

Then create a line chart visual first, and put the related field to the visual. and sort the visual ascending by BarchID, open the marker.

vxinruzhumsft_1-1730258427703.png

vxinruzhumsft_2-1730258472725.png

Then click the viusal, then change it to clustered column visual.

Then put the color_flag measure to the column color format.

vxinruzhumsft_3-1730258523692.png

 

vxinruzhumsft_4-1730258591940.png

 

Then click the visual , change it to line chart visual again.

Output

vxinruzhumsft_5-1730258814986.png

Best Regards!

Yolo Zhu

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

 

 

 

 

 

 

Hi @Anonymous Out of curiosity, how shall we highlight the next data point (8th data point) instead of highlighting the 7th data point if 7 consecutive decreasing or increasing found?  I understood the logics being used in all 4 measures and I was adjusting the _decrement & _increment measures to display 1 to the very next Id of 7th consective decreasing/increasing batch id. But ending up in invalid data only. could you pls. provide solution on this?

Hi @Anonymous Great yaar! This works. Thank you so much! @rajendraongole1  Thanks to you as well for helping me on this! Thank You both !!!

rajendraongole1
Super User
Super User

Hi @SelviPrabhu - The issue in your current approach is that Earlier is used in a way that might not give the intended comparison between the current and previous values across consecutive rows

first lets create a measure for Consecutive Decreases

ConsecutiveDecrease =
VAR CurrentID = MAX('Batch Table'[BatchID])
VAR ConsecutiveDecreaseCount =
SUMX(
FILTER(
'Batch Table',
'Batch Table'[BatchID] >= CurrentID - 6 && 'Batch Table'[BatchID] <= CurrentID
),
IF(
'Batch Table'[TotalOrders] <
CALCULATE(
MAX('Batch Table'[TotalOrders]),
FILTER('Batch Table', 'Batch Table'[BatchID] = 'Batch Table'[BatchID] - 1)
),
1,
0
)
)
RETURN
IF(ConsecutiveDecreaseCount = 6, 1, 0)

 

Similarly, the following measure will count consecutive increases by checking the previous values

ConsecutiveIncrease =
VAR CurrentID = MAX('Batch Table'[BatchID])
VAR ConsecutiveIncreaseCount =
SUMX(
FILTER(
'Batch Table',
'Batch Table'[BatchID] >= CurrentID - 6 && 'Batch Table'[BatchID] <= CurrentID
),
IF(
'Batch Table'[TotalOrders] >
CALCULATE(
MAX('Batch Table'[TotalOrders]),
FILTER('Batch Table', 'Batch Table'[BatchID] = 'Batch Table'[BatchID] - 1)
),
1,
0
)
)
RETURN
IF(ConsecutiveIncreaseCount = 6, 1, 0)

 

you can use both the ConsecutiveDecrease and ConsecutiveIncrease measures in a final HighlightPoint measure that will return 1

 

HighlightPoint =
IF(
[ConsecutiveIncrease] = 1 || [ConsecutiveDecrease] = 1,
1,
0

)

in your visualization line chart add the highlight and values measure and in conditional formatting make sure that highlight point is 1.

 

I hope this works for 7 consecutive increases or decreases





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi @rajendraongole1 Now I can see 1 at the total level only. I've applied the conditional formatting at HighlightPoint measure level if One then Red color and for 0's Blue. You can see all of the values are displaying as blue only where as HighlightPoint value for BatchId 10007 should be displayed in red colour because its 7th continuos decreasing point. Since its having the values as 0 instead of 1 this point also displaying blue color. Could you pls. check and help on this?

SelviPrabhu_0-1730214643717.png

 

Hi @rajendraongole1 BatchId is in INT format and in Table visual I'm not aggregating it. Is that causing this issue? I need to use this BatchId in X axis in Line chart so it should be converted to Text format. If I covert BatchId into text then getting below issue on the measure becuase we are applying math operations on batchid. so we need to apply conversions in our measure I guess. Could you pls. verify on this?

SelviPrabhu_1-1730215109730.png

 

Hi @rajendraongole1 But again it shows me 0 at 7th data point. not 1. Pls. refer the second page where it shows 0 for 7th data point and in first page at 7th data points its not highlighting the data value in red color. Thanks in Advance!

Hi @SelviPrabhu - can you please check the attached pbix file. 

 

rajendraongole1_0-1730210247315.png

rajendraongole1_1-1730210286529.png

 

Hope this works well.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors