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
JonSwed
Advocate II
Advocate II

Counting number of consecutive days

Hi all,

I have a chat function where I want to count the number of consective days that pairs were chatting.

My data looks something like this:

Skärmavbild 2020-11-16 kl. 18.37.29.png

 

 

 

 

 

 

 

 

 

 

 

and the desired output would be like this:

Skärmavbild 2020-11-16 kl. 18.38.42.png

 

 

 

Where I show the maximum number of days where the pairs of users consecutively messaged each other.

Any help gratefully received, thanks.

 

7 REPLIES 7
JonSwed
Advocate II
Advocate II

Thanks for the input here. Currentlly testing the different solutions. Again, many thanks.

V-lianl-msft
Community Support
Community Support

Hi @JonSwed ,

 

Based on your description, you want to figure out how many days send messages to each other.

You can try to do this by creating a calculated column to get the number of messages sent in the next day, and then use the current day and the next day as filter to determine whether sending messages continuously.

nextday = CALCULATE(LASTNONBLANK('Table (2)'[Total Messages],1),
FILTER('Table (2)',
EARLIER('Table (2)'[Date])='Table (2)'[Date]-1
&&'Table (2)'[Name]=EARLIER('Table (2)'[Name])))
Measure = COUNTROWS(FILTER('Table (2)','Table (2)'[Total Messages]>0&&'Table (2)'[nextday]>0))+1

V-lianl-msft_0-1605761961215.png

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

camargos88
Community Champion
Community Champion

@FrankAT ,

 

This thread was opened by @JonSwed . Check the first message.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



FrankAT
Community Champion
Community Champion

Hi @camargos88 

which sequence would you prefer, the first, the second, the max consecutive sequence, the amount of tied consecutive sequences or the sum of them?

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

FrankAT
Community Champion
Community Champion

Hi @camargos88 

I think you can do it like this:

 

16-11-_2020_22-19-38.png

 

Number of Consecutive Days = 
CALCULATE(
    COUNTROWS('Data Table'),
    FILTER(
        'Data Table',
        'Data Table'[Total messages] > 0
    )
)

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

@FrankAT ,

 

This doesn't guarantee the date's sequence. 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



camargos88
Community Champion
Community Champion

@JonSwed ,

 

Try this measure:

 

_Consecutive Days = 
VAR _tb = 
    SUMMARIZE(
        'Table', 
         'Table'[User],
        'Table'[Date], 
        "Consecutive", IF('Table'[Date] - CALCULATE(MAX('Table'[Date]), FILTER(ALL('Table'[Date]), 'Table'[Date] < EARLIER('Table'[Date]))), 1, 0),
        "TotalMessages", SUM('Table'[Total Messages])
        )
RETURN COUNTX(FILTER(_tb, ([Consecutive] = 1 || [Consecutive] = BLANK()) && [TotalMessages] > 0), [TotalMessages])

 

 

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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