Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Problem Description:
There is a set within a group with start and end dates. When the end date and next start date have a gap of more than one day, these dates need to be combined.
Solution:
For the solution, we need to create the partition of continuous dates.
Steps :
Create a flag to check that the dates are continuous. This flag needs to be bidirectional for a statement/line to check a 3-day gap on either side. We will get two columns:
Continuous Flag = var _1 = DATEDIFF(Sheet1[End Date] , MINX(FILTER(Sheet1, ([Start Date]>=EARLIER(Sheet1[End Date])+1 && [Start Date]<=EARLIER(Sheet1[End Date])+3)&& [Group]=EARLIER(Sheet1[Group]) ),([End Date])),DAY) +DATEDIFF( Sheet1[Start Date] -1, maxx(FILTER(Sheet1, ( [end Date]<=EARLIER(Sheet1[Start Date])-1 && [end Date]>=EARLIER(Sheet1[Start Date])-3) && [Group]=EARLIER(Sheet1[Group])) ,EARLIER([Start Date])),DAY)
Var _3 = datediff(maxx(FILTER(Sheet1,[End Date]<EARLIER([Start Date]) && [Group] =EARLIER(Sheet1[Group])),[End Date]),[Start Date].[Date],DAY)
return if(_3<=3, BLANK(),1)+0
Date :
Continuous Date = COALESCE( MINX(FILTER(Sheet1, ([Start Date]>=EARLIER(Sheet1[End Date])+1 && [Start Date]<=EARLIER(Sheet1[End Date])+3) && [Group]=EARLIER(Sheet1[Group]) ),([start Date]))
,maxx(FILTER(Sheet1, ( [end Date]<=EARLIER(Sheet1[Start Date])-1 && [end Date]>=EARLIER(Sheet1[Start Date])-3)&& [Group]=EARLIER(Sheet1[Group])) ,EARLIER([End Date])))
Use the above measures to calculate start date
New Start Date = Var _1 = maxx(FILTER(Sheet1,[Group] =EARLIER(Sheet1[Group]) && [Continuous Date] <=EARLIER(Sheet1[Continuous Date])&& not(ISBLANK([Continuous Date])) && [Continuous Flag]<>EARLIER([Continuous Flag])),Sheet1[Start Date])
Var _2 = minx(FILTER(Sheet1,[Group] =EARLIER(Sheet1[Group]) && [Continuous Date] <=EARLIER(Sheet1[Continuous Date]) && [Continuous Flag]=EARLIER([Continuous Flag]) && not(ISBLANK([Continuous Flag])) ),Sheet1[Start Date])
Var _3 =SWITCH(True(),
[Continuous Flag]=1,[Start Date],
(ISBLANK(_1) && [Continuous Flag]=0),_2,
not(ISBLANK(_1)),_1,
[Start Date])
return if(ISBLANK(_3),[Start Date],_3)
Calculate End Date with help from Start Date
New End Date = maxx(FILTER(Sheet1,[Group]=EARLIER([Group]) && [New Start Date]=EARLIER([New Start Date])),[End Date])
Let us know what you think about these measures. Share your thoughts on different use cases of the continuous streak.
You can get all my posts at https://community.powerbi.com/t5/Data-Stories-Gallery/Blog-Analysis/m-p/1265567#M4403
You can find the file at:https://community.powerbi.com/t5/Quick-Measures-Gallery/Power-BI-Continuous-Streak-Three-Multi-Day-D...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.