cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent 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 "bad" indicators. I don't care so much about single instances, good or bad. I'd like an ouput similar to the Result column below.

If measure would work better, that's fine with me. But it's a calculation I'm going to use quite a bit and, ultimately, I'd like to be able to pull some numbers that say "we had X amount of 'consecutive bads' this month on Y amount of servers and the average number of consecutives (in terms of duration, 2.3 consecutive bads or whatever) was Z".

1 ACCEPTED SOLUTION
Super User

Step one Second Version =
VAR currentserver = Data[Server]
VAR currentdate = Data[Date]
VAR flagcumulate =
IF (
Data[Indicator] = "good",
BLANK (),
SUMX (
SUMMARIZE (
FILTER ( Data, Data[Server] = currentserver && Data[Date] <= currentdate ),
Data[Server],
Data[Date],
Data[Indicator]
),
"@flag", IF ( Data[Indicator] = "good", 1, 0 )
),
[@flag]
)
)
RETURN
flagcumulate

Result 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 )
RETURN
IF ( Data[Indicator] = "good" || result <= 1, "Don't care", result & "Bads" )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

Visit my LinkedIn page by clicking here.

Schedule a meeting with me to discuss further by clicking here.

4 REPLIES 4
Super User

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 (
&& MAXX (
FILTER (
Data,
Data[Server] = currentserver
&& RANKX ( FILTER ( data, Data[Server] = currentserver ), Data[Date],, DESC ) = rankbydate + 1
),
Data[Indicator]
1
)
VAR flagtwo =
IF (
&& MAXX (
FILTER (
Data,
Data[Server] = currentserver
&& RANKX ( FILTER ( data, Data[Server] = currentserver ), Data[Date],, DESC ) = rankbydate - 1
),
Data[Indicator]
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" )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

Visit my LinkedIn page by clicking here.

Schedule a meeting with me to discuss further by clicking here.

Frequent 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.

Super User

Step one Second Version =
VAR currentserver = Data[Server]
VAR currentdate = Data[Date]
VAR flagcumulate =
IF (
Data[Indicator] = "good",
BLANK (),
SUMX (
SUMMARIZE (
FILTER ( Data, Data[Server] = currentserver && Data[Date] <= currentdate ),
Data[Server],
Data[Date],
Data[Indicator]
),
"@flag", IF ( Data[Indicator] = "good", 1, 0 )
),
[@flag]
)
)
RETURN
flagcumulate

Result 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 )
RETURN
IF ( Data[Indicator] = "good" || result <= 1, "Don't care", result & "Bads" )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

Visit my LinkedIn page by clicking here.

Schedule a meeting with me to discuss further by clicking here.

Frequent Visitor

Thank You! That's exactly what I needed.

Your solution is much cleaner than many I've seen.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

#### Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors