Forum Discussion
Grouping by consecutive dates into date ranges
- 8 years ago
Essentially I have added 3 calculated columns to identify the boundaries of consective dates which can then be used for Groupings
SeriesBoundaries = VAR PriorName = CALCULATE ( VALUES ( TableName[Name] ), FILTER ( ALLEXCEPT ( TableName, TableName[Name] ), TableName[SeriesStart] = EARLIER ( TableName[SeriesStart] ) - 1 ) ) VAR NextName = CALCULATE ( VALUES ( TableName[Name] ), FILTER ( ALLEXCEPT ( TableName, TableName[Name] ), TableName[SeriesStart] = EARLIER ( TableName[SeriesStart] ) + 1 ) ) RETURN IF ( PriorName <> TableName[Name], "Series Start", IF ( NextName <> TableName[Name], "Series End" ) ) - 8 years ago
HI lkarolak
Please change the formua of Series Start as follows
SeriesStart = VAR PreviousDate = CALCULATE ( MAX ( TableName[Date ] ), FILTER ( TableName, TableName[Date ] < EARLIER ( TableName[Date ] ) ) ) VAR PreviousName = CALCULATE ( FIRSTNONBLANK ( TableName[Name], 1 ), FILTER ( TableName, TableName[Date ] = PreviousDate ) ) VAR myrank = RANKX ( TableName, TableName[Date ],, ASC, DENSE ) RETURN IF ( PreviousDate <> TableName[Date ] - 1 && TableName[Name] = PreviousName, myrank + 1, myrank )
Thank you Zubair_Muhammad, it almost works :)
This is the actual initial data that I have:
But then I get this after using the approach you suggested. The first row is exactly what I want, however, the "single" ones are still listed:
What am I doing wrong?
Thanks!
- Zubair_Muhammad8 years agoCommunity Champion
HI lkarolak
Please change the formua of Series Start as follows
SeriesStart = VAR PreviousDate = CALCULATE ( MAX ( TableName[Date ] ), FILTER ( TableName, TableName[Date ] < EARLIER ( TableName[Date ] ) ) ) VAR PreviousName = CALCULATE ( FIRSTNONBLANK ( TableName[Name], 1 ), FILTER ( TableName, TableName[Date ] = PreviousDate ) ) VAR myrank = RANKX ( TableName, TableName[Date ],, ASC, DENSE ) RETURN IF ( PreviousDate <> TableName[Date ] - 1 && TableName[Name] = PreviousName, myrank + 1, myrank ) - lkarolak8 years agoFrequent Visitor
Zubair_Muhammad My mistake, forgot to set the filter on visual level to match the "SeriesStart".
It's working good now, thanks a lot for your support!
- lkarolak8 years agoFrequent Visitor
Zubair_Muhammad Sorry, actually there is something missing still.
If we have this example:
Date Name
----------------------
01.04.2018 Claudia
03.04.2018 Claudia
Then this is treated as one range (01.04.2018-03.04.2018), although it should be two separate 1 day ranges.
See the example file here: click
Thank you!
- Zubair_Muhammad8 years agoCommunity Champion
- lkarolak8 years agoFrequent Visitor
Thank you Zubair_Muhammad, that was it!!
- Anonymous7 years agoNot applicable
Hi Zubair_Muhammad,
I have a very similar problem with one critical difference, my source data can have multiple transaction on the same date. See below:
Original RequirementMy Requirement
In my requirement, I want to ignore the second transaction for Mark on the 1st March 2018. This is the result I need:
Date Name SeriesStart SeriesBoundaries Last Date Thursday, 01 March 2018 Mark 1 Series Start Thursday, 01 March 2018 Thursday, 01 March 2018 Mark 1 Saturday, 03 March 2018 Mark 3 Series Start Saturday, 03 March 2018 Wednesday, 07 March 2018 John 3 Series Start Thursday, 08 March 2018 Thursday, 08 March 2018 John 4 Series End Thursday, 15 March 2018 Steve 5 Series Start Thursday, 15 March 2018 Tuesday, 20 March 2018 Mark 6 Series Start Thursday, 22 March 2018 Wednesday, 21 March 2018 Mark 7 Thursday, 22 March 2018 Mark 8 Series End Sunday, 01 April 2018 Claudia 9 Series Start Sunday, 01 April 2018 Tuesday, 03 April 2018 Claudia 11 Series Start Tuesday, 03 April 2018 How would you change your code to handle this situation? I have re-uploaded your solution with my requirement here:
Thanks
- srikanth_pendem5 years agoNew Member
Hi Zubair_Muhammad ,
I am not able to get that lastDate part. Could you please share the file?
thanks,
Srikanth