# Thread: Countif in power bi Thanks: 0 Likes: 0

1. ## Re: Countif in power bi

Originally Posted by pinarello
Yes, the original order should be retained at the end
Are you zuriqi?

2. ## Re: Countif in power bi

zuriqi last replied on 30 May. But that's how I understood the task.

But I don't care, because when I help, it's primarily to learn for myself. And I also succeeded very well with this thread

3. ## Re: Countif in power bi

Originally Posted by pinarello
But that's how I understood the task.
But not me, in PBI it doesn't matter too much sort order

4. ## Re: Countif in power bi

Try this:

Code:
```let
Source = Excel.CurrentWorkbook(){[Name="Tabelle1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ColA", type text}}),
#"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "ColA", "ColA - Copy"),
#"Grouped Rows" = Table.Group(#"Added Index", {"ColA - Copy"}, {{"CountAll", each _, type table [ColA=text, #"ColA - Copy"=text, Index=number]}}),
#"Expanded Index2" = Table.ExpandTableColumn(#"Removed Columns", "Index2", {"ColA", "Index", "Index2"}, {"ColA", "Index", "ColB"}),
#"Sorted Rows" = Table.Sort(#"Expanded Index2",{{"Index", Order.Ascending}}),
#"Removed Columns1" = Table.RemoveColumns(#"Sorted Rows",{"ColA", "Index"})
in
#"Removed Columns1"```
On my computer it lasts for:

Excelguru.ca solution - about 33 seconds
My solution - 5 seconds

5. ## Re: Countif in power bi

That's a great solution, too. At the test with 960.000 lines, it took about 13 seconds. Almost identical with the first solution from cyborgski, which takes about 12 seconds on my computer. Only the second solution of cyborgski needs about 40 seconds for this amount of data.

At the test with 120.000 lines all 3 solutions are, from the feeling, equally fast.