Forum Discussion
RShackelford
5 years agoFrequent Visitor
Yet Another Consecutive Values Question
I've seen this question asked quite a bit, but I can't seem to find a solution that works for me or doesn't thoroughly confuse me. I'd like to create a calculated column that counts consecutive "...
- 5 years ago
Hi, RShackelford
Thank you for your feedback.
Please check the below.
Step one Second Version =VAR currentserver = Data[Server]VAR currentdate = Data[Date]VAR flagcumulate =IF (Data[Indicator] = "good",BLANK (),SUMX (ADDCOLUMNS (SUMMARIZE (FILTER ( Data, Data[Server] = currentserver && Data[Date] <= currentdate ),Data[Server],Data[Date],Data[Indicator]),"@flag", IF ( Data[Indicator] = "good", 1, 0 )),[@flag]))RETURNflagcumulateResult CC Second Version =VAR currentstepone = Data[Step one Second Version]VAR currentserver = Data[Server]VAR newtable =FILTER (Data,Data[Server] = currentserver&& Data[Step one Second Version] == currentstepone)VAR result =COUNTROWS ( newtable )RETURNIF ( Data[Indicator] = "good" || result <= 1, "Don't care", result & "Bads" )
Jihwan_Kim
5 years agoSuper User
Hi, RShackelford
Please check the below picture and the sample pbix file's link down below. It is for creating a new column.
Step one CC =
VAR currentserver = Data[Server]
VAR rankbydate =
RANKX ( FILTER ( data, Data[Server] = currentserver ), Data[Date],, DESC )
VAR flag =
IF (
Data[Indicator] = "Bad"
&& MAXX (
FILTER (
Data,
Data[Server] = currentserver
&& RANKX ( FILTER ( data, Data[Server] = currentserver ), Data[Date],, DESC ) = rankbydate + 1
),
Data[Indicator]
) = "Bad",
1
)
VAR flagtwo =
IF (
Data[Indicator] = "Bad"
&& MAXX (
FILTER (
Data,
Data[Server] = currentserver
&& RANKX ( FILTER ( data, Data[Server] = currentserver ), Data[Date],, DESC ) = rankbydate - 1
),
Data[Indicator]
) = "Bad",
1
)
RETURN
flag + flagtwo
Result CC =
VAR currentserver = Data[Server]
VAR steponeCCcountrow =
COUNTROWS (
FILTER ( Data, Data[Server] = currentserver && Data[Step one CC] <> BLANK () )
)
RETURN
IF ( NOT ISBLANK ( Data[Step one CC] ), steponeCCcountrow & " Bads" )
- RShackelford5 years agoFrequent Visitor
Thank You Jihwan_Kim!
That worked for the dataset I provided in the example. However, I need to separate out the different consecutive instances within the same server (See server C in the table below). My apologies, I should have specified this in the original example.
Server Date Indicator Result A 1/1/2021 Good Don't care A 1/2/2021 Bad Don’t care A 1/3/2021 Good Don't care A 1/4/2021 Bad 2 Bads A 1/5/2021 Bad 2 Bads B 1/1/2021 Good Don't care B 1/2/2021 Good Don't care B 1/3/2021 Good Don't care B 1/4/2021 Bad Don't care B 1/5/2021 Good Don't care C 1/1/2021 Bad Don't care C 1/2/2021 Good Don't care C 1/3/2021 Bad 3 Bads C 1/4/2021 Bad 3 Bads C 1/5/2021 Bad 3 Bads C 1/6/2021 Good Don't care C 1/7/2021 Bad 2 Bads C 1/8/2021 Bad 2 Bads - Jihwan_Kim5 years agoSuper User
Hi, RShackelford
Thank you for your feedback.
Please check the below.
Step one Second Version =VAR currentserver = Data[Server]VAR currentdate = Data[Date]VAR flagcumulate =IF (Data[Indicator] = "good",BLANK (),SUMX (ADDCOLUMNS (SUMMARIZE (FILTER ( Data, Data[Server] = currentserver && Data[Date] <= currentdate ),Data[Server],Data[Date],Data[Indicator]),"@flag", IF ( Data[Indicator] = "good", 1, 0 )),[@flag]))RETURNflagcumulateResult CC Second Version =VAR currentstepone = Data[Step one Second Version]VAR currentserver = Data[Server]VAR newtable =FILTER (Data,Data[Server] = currentserver&& Data[Step one Second Version] == currentstepone)VAR result =COUNTROWS ( newtable )RETURNIF ( Data[Indicator] = "good" || result <= 1, "Don't care", result & "Bads" )- RShackelford5 years agoFrequent Visitor
Thank You! That's exactly what I needed.
Your solution is much cleaner than many I've seen.