Forum Discussion
greenmonsta
4 years agoFrequent Visitor
count data across mutiple ranges
Hi All, I am trying to solve the following in Power Query. In the data table I have Ticket Number, the date the ticket was created and the date the ticket was resolved. If the resolved cell is blan...
- 4 years ago
Hi greenmonsta ,
didn't get that requirement before.
You can adjust like this:let Source = Sprints, #"Added Custom" = Table.AddColumn( Source, "Days", each {Number.From([Start]) .. Number.From([End])} ), #"Expanded Days" = Table.ExpandListColumn(#"Added Custom", "Days"), #"Changed Type" = Table.TransformColumnTypes(#"Expanded Days", {{"Days", type date}}), Merge = Table.NestedJoin( #"Changed Type", {"Days"}, Tickets_Exanded, {"Dates"}, "Starts", JoinKind.LeftOuter ), Expanded = Table.ExpandTableColumn(Merge, "Starts", {"Ticket Num", "Opened Date", "Closed Date"}, {"Ticket Num", "Opened Date", "Closed Date"}), AddOpened = Table.AddColumn(Expanded, "Opened", each if [Days] = [Opened Date] then [Opened Date] else null), AddClosed = Table.AddColumn(AddOpened, "Closed", each if [Days] = [Closed Date] then [Closed Date] else null), AddIgnoreForOpen = Table.AddColumn(AddClosed, "IgnoreForOpen", each [Opened Date] >= [Start] and [Closed Date] <= [End]), #"Grouped Rows" = Table.Group( AddIgnoreForOpen, {"Sprint", "Start", "End"}, { { "Tickets Created", each List.Count(List.Distinct(List.Select(_[Opened], each _ <> null))), Int64.Type }, { "Tickets Closed", each List.Count(List.Distinct(List.Select(_[Closed], each _ <> null))), Int64.Type }, {"Tickets Open", each List.Count(List.Distinct(Table.SelectRows(_, (x) => not x[IgnoreForOpen])[Ticket Num])), Int64.Type} } ) in #"Grouped Rows"
Also check enclosed file.
ImkeF
4 years agoCommunity Champion
Hi greenmonsta ,
I've used Gregs file, so you'll find both our solutions in it.
The Power Query solution is in Table "Result".
greenmonsta
4 years agoFrequent Visitor
Hi ImkeF . Thank you for pointing out the Power Query Result. I see it now. This is so much better than the way I was attacking it. My tables were really wide. This is much more efficient, really great insight. I am not getting the "Tickets Open" column to calculate correctly though. I believe it is taking a distinct count, but if a ticket were opened and closed in the same sprint it should not be counted. Any thoughts on how to solve this?