Forum Discussion
awais692
Jul 26, 2021Copper Contributor
Count if formula for multiple columns in power query
How to write a formula =countif(A2:M2,"<=15") in power query?
SergeiBaklan
Mar 11, 2023Diamond Contributor
As variant you may add custom column to Events with OpenWindow table in each record, expand it, add one more custom column to check if the event is in Window and group the result by events taking max value from the latest column. Thus if any TRUE exists it will be returned, otherwise FALSE.
let
getOpenWindow = Excel.CurrentWorkbook(){[Name="OpenWindow"]}[Content],
changeOpenWindowType = Table.TransformColumnTypes(
getOpenWindow,
{
{"from", type time},
{"to", type time}
}),
getEvents = Excel.CurrentWorkbook(){[Name="events"]}[Content],
changeEventsType = Table.TransformColumnTypes(
getEvents,
{{"time", type time}}),
addOpenWindow = Table.AddColumn(
changeEventsType,
"Custom",
each changeOpenWindowType),
expandWindows = Table.ExpandTableColumn(
addOpenWindow,
"Custom",
{"from", "to"},
{"from", "to"}),
checkIfInWindow = Table.AddColumn(
expandWindows,
"IsIn",
each [time] >= [from] and [time] <= [to],
Logical.Type),
groupBack = Table.Group(
checkIfInWindow, {"time"},
{
{"inWindowTime", each List.Max([IsIn]), type logical}
})
in
groupBack
Result is
Szagal
Mar 12, 2023Copper Contributor
I came to the point of "checkIfInWindow" by clicking :).
Then row multiplied - I considered it a mistake.
So after grouping by max(IsIn) stay 1 (true), it seems to work.
Thanks
- SergeiBaklanMar 13, 2023Diamond Contributor
Didn't catch which exactly mistake did you have. However, good to know if it works finally.