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 Anonymous - 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
- Anonymous1 year agoNot applicable
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!
- rajendraongole11 year agoSuper User
Hi Anonymous - can you please check the attached pbix file.
Hope this works well.
- Anonymous1 year agoNot applicable
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?
- Anonymous1 year agoNot applicable
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?