Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi All
I'm new to the forum and am currently enrolled in a Data Analyst apprenticeship with my employer (due to finish in the next few months). I have been using Power Query for the past couple of years and have recently started my journey with Power BI/DAX. I am running into an issue where i want to group service lines together from our system into proper "episodes". In the test example I've attached below, the same ID number has had 4 service lines with the same provider, giving me 2 actual episodes (1st April to 14th June and then again from 18th June to 30th June). Thus, I want to group the service lines together by ID number/name/provider with the min start date and max end date, but only where there are no gaps between one service lines end date and the next lines start date.
I am hitting a bit of a brick wall trying to get my head around how I can go about this. I have done some googling and plenty of searches on YouTube, but haven't managed to find a solution so far.
Any help would be much appreciated
Thanks
Cal
Solved! Go to Solution.
Hi
let
Source = YourSource,
#"EndDate+1" = Table.AddColumn(Source, "End Date+1", each Date.AddDays([End Date],1)),
Join = Table.NestedJoin(#"EndDate+1", {"ID Number", "Start Date"}, #"EndDate+1", {"ID Number", "End Date+1"}, "NextRow?", JoinKind.LeftOuter),
Test_Group = Table.TransformColumns(Join,{{"NextRow?", each Table.IsEmpty(_), type logical}}),
LocalGroup = Table.Group(
Test_Group,
{"ID Number", "Name", "Provider", "NextRow?"},
{{"Start Date", each List.Min([Start Date]), type date}, {"End Date", each List.Max([End Date]), type date}},
GroupKind.Local,
(x,y) => if y[#"NextRow?"] then 1 else 0)
in
LocalGroup
Stéphane
Brilliant, works as needed. Thanks so much
Hi
let
Source = YourSource,
#"EndDate+1" = Table.AddColumn(Source, "End Date+1", each Date.AddDays([End Date],1)),
Join = Table.NestedJoin(#"EndDate+1", {"ID Number", "Start Date"}, #"EndDate+1", {"ID Number", "End Date+1"}, "NextRow?", JoinKind.LeftOuter),
Test_Group = Table.TransformColumns(Join,{{"NextRow?", each Table.IsEmpty(_), type logical}}),
LocalGroup = Table.Group(
Test_Group,
{"ID Number", "Name", "Provider", "NextRow?"},
{{"Start Date", each List.Min([Start Date]), type date}, {"End Date", each List.Max([End Date]), type date}},
GroupKind.Local,
(x,y) => if y[#"NextRow?"] then 1 else 0)
in
LocalGroup
Stéphane
Many thanks for your response. I will have a play with this later on and will accept solution if all working 😀
Check out the July 2025 Power BI update to learn about new features.