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 ,
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.
greenmonsta
4 years agoFrequent Visitor
ImkeF You are the bomb! Thank you! I leaned a lot here, not only your solution but the your style is awsome! Thanks again.