Forum Discussion
Highlight 7th data point based on consecutive increases or decreases in line chart in PowerBI
- Anonymous1 year ago
Hi,
Thanks for the solution rajendraongole1 offered,and i want to offer some more infotmation for user to refer to.
hello Anonymous , you can refer to the following sample.
Sample data
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.
Then click the viusal, then change it to clustered column visual.
Then put the color_flag measure to the column color format.
Then click the visual , change it to line chart visual again.
Output
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,
Thanks for the solution rajendraongole1 offered,and i want to offer some more infotmation for user to refer to.
hello Anonymous , you can refer to the following sample.
Sample data
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.
Then click the viusal, then change it to clustered column visual.
Then put the color_flag measure to the column color format.
Then click the visual , change it to line chart visual again.
Output
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.
- Anonymous1 year agoNot applicable
Hi Anonymous Great yaar! This works. Thank you so much! rajendraongole1 Thanks to you as well for helping me on this! Thank You both !!!
- Anonymous1 year agoNot applicable
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?