Forum Discussion
Finding repeated values over consecutive dates
- 8 years ago
Maybe you want to learn some Power Query as well? :smileywink:
Actually, Power Query has a function with a special parameter to count consecutive values: Table.Group with 4th parameter GroupKind. If that parameter is set to GroupKind.Local, Table.Group will group consecutive values, so each change in value will become a new group.
So, the challenge is to turn your row values into nested tables and then fire Table.Group on those tables.
This is done with the following query and function GetAlert below. Note that the nested tables are created from all row values except the first 1 (Name). Adjust the Source with your table (I used Power Query in Excel but the rest of the code is fine for Power BI Desktop as well).
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Added Custom" = Table.AddColumn(Source, "Tables", each Table.FromColumns({List.Skip(Record.FieldValues(_))},{"Values"})),
#"Invoked Custom Function" = Table.AddColumn(#"Added Custom", "Alert", each GetAlert([Tables])),
#"Removed Columns" = Table.RemoveColumns(#"Invoked Custom Function",{"Tables"})
in
#"Removed Columns"
Function GetAlert:
(MyTable as table) as number =>
let
#"Grouped Rows" = Table.Group(MyTable, {"Values"}, {{"Count", each Table.RowCount(_), type number}}, GroupKind.Local),
#"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Values] = 0 and [Count] >= 5),
Alert = if Table.IsEmpty(#"Filtered Rows") then 0 else 1
in
Alert
You're absolutely right. I need to learn power query mainly because I'm also facing a ton of memory issues, and even though I'm trying to reduce my fact tables and optimize, I need to work with power query before even bothering with the rest of it.
As for the functions you posted below, Ashish's solution gets me up and running, and ultimately achieves what I want, but as I'm interested in learning so I can A.) Become self-sufficient and B.) Contribute back to the community, I'll definitely play around with the query as you have demonstrated.
Thanks for your help and attention. I appreciate it greatly.