let
lst = List.Buffer(Excel.CurrentWorkbook(){[Name="Table4"]}[Content][Style]),
lst1 = List.Accumulate(List.Skip(lst), {{lst{0},1, 2}}, (s,c)=> let ll = List.Last(s){2} in s & {{c, List.Count(List.Select(List.FirstN(lst, ll), each _ = c)), ll +1}}),
Result = Table.FromColumns(List.FirstN(List.Zip(lst1),2), {"Style","Occurence"})
in
Result
Book1 | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | Style | Style | Occurence | ||||
2 | B | B | 1 | ||||
3 | B | B | 2 | ||||
4 | C | C | 1 | ||||
5 | E | E | 1 | ||||
6 | D | D | 1 | ||||
7 | C | C | 2 | ||||
8 | C | C | 3 | ||||
9 | A | A | 1 | ||||
10 | B | B | 3 | ||||
11 | E | E | 2 | ||||
12 | E | E | 3 | ||||
13 | E | E | 4 | ||||
14 | A | A | 2 | ||||
15 | D | D | 2 | ||||
16 | A | A | 3 | ||||
17 | B | B | 4 | ||||
18 | D | D | 3 | ||||
19 | A | A | 4 | ||||
20 | D | D | 4 | ||||
21 | C | C | 4 | ||||
22 | |||||||
Sheet4 |
@JGordon11 I love your M Code, but it is REALLY obscure. I would love to see your code as above, and also a step by step using the UI as much as possible. Still, the code is amazing!Power Query:let lst = List.Buffer(Excel.CurrentWorkbook(){[Name="Table4"]}[Content][Style]), lst1 = List.Accumulate(List.Skip(lst), {{lst{0},1, 2}}, (s,c)=> let ll = List.Last(s){2} in s & {{c, List.Count(List.Select(List.FirstN(lst, ll), each _ = c)), ll +1}}), Result = Table.FromColumns(List.FirstN(List.Zip(lst1),2), {"Style","Occurence"}) in Result
Book1
A B C D E 1 Style Style Occurence 2 B B 1 3 B B 2 4 C C 1 5 E E 1 6 D D 1 7 C C 2 8 C C 3 9 A A 1 10 B B 3 11 E E 2 12 E E 3 13 E E 4 14 A A 2 15 D D 2 16 A A 3 17 B B 4 18 D D 3 19 A A 4 20 D D 4 21 C C 4 22 Sheet4