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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
spandana
Frequent Visitor

Consecutive Days an event has occured

Hello everyone,   I have been struggling to find a solution to this.  I have a table with 2 columns. The dates [1/1/2021, 1/2/2021.. ], Another column saying 1 if an event has occurred, and blank otherwise. I have been trying to find a way to calculate the max consecutive days an event has occurred.    It would be great if I could get a solution

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @spandana ;

According to your desscription, I think Jihwan_Kim’s reply is a good idea. In addition, you also could create a column and measure to calculate. as follows:

1.create a column

group = SUMX(FILTER(ALL(Data),[Date]<=EARLIER(Data[Date])),[Event]-1)

2.create a measure

maxDays = 
var _table=SUMMARIZE('Data',[group],"count",CALCULATE(COUNTROWS('Data'),FILTER(ALL(Data),[group]=MAX([group]))))
return MAXX(_table,[count])

The final output is shown below:

vyalanwumsft_0-1625537995386.png

Best Regards,
Community Support Team_ Yalan Wu
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

3 REPLIES 3
spandana
Frequent Visitor

Thank you! Really helpful!

v-yalanwu-msft
Community Support
Community Support

Hi, @spandana ;

According to your desscription, I think Jihwan_Kim’s reply is a good idea. In addition, you also could create a column and measure to calculate. as follows:

1.create a column

group = SUMX(FILTER(ALL(Data),[Date]<=EARLIER(Data[Date])),[Event]-1)

2.create a measure

maxDays = 
var _table=SUMMARIZE('Data',[group],"count",CALCULATE(COUNTROWS('Data'),FILTER(ALL(Data),[group]=MAX([group]))))
return MAXX(_table,[count])

The final output is shown below:

vyalanwumsft_0-1625537995386.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Picture1.png

 

Event consequtive max occurrence =
VAR _eventflagcumulatetable =
ADDCOLUMNS (
SUMMARIZE ( Data, Data[Date] ),
"@eventflagcumulate",
CALCULATE (
SUMX (
FILTER ( ALL ( Data ), Data[Date] <= MAX ( Data[Date] ) ),
Data[Event] - 1
)
)
)
VAR _groupbyeventflagcumulate =
GROUPBY (
_eventflagcumulatetable,
[@eventflagcumulate],
"@countrows", SUMX ( CURRENTGROUP (), 1 )
)
RETURN
MAXX(_groupbyeventflagcumulate, [@countrows])
 
 
 
 

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.


Go to My LinkedIn Page


Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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