Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Fabric community is now in read-only for platform upgrade. Learn more

Reply
Anonymous
Not applicable

Replicate countif excel function in PowerQuery

Hi,

 

I'm trying to replicate countif excel function into powerquery.

=COUNTIF(C:C,C3)

 

End result should be as below

ItemCount of Items
A4
A4
A4
A4
B4
B4
B4
B4
B4
1 ACCEPTED SOLUTION
wdx223_Daniel
Community Champion
Community Champion

=let a=Table.Buffer(Table.Group(PreviousStepName,"Item",{"n",Table.RowCount})) in Table.AddColumn(PreviousStepName,"Count of Items",each a{[Item=[Item]]}[n])

View solution in original post

4 REPLIES 4
wdx223_Daniel
Community Champion
Community Champion

=let a=Table.Buffer(Table.Group(PreviousStepName,"Item",{"n",Table.RowCount})) in Table.AddColumn(PreviousStepName,"Count of Items",each a{[Item=[Item]]}[n])

HotChilli
Community Champion
Community Champion

Is that a mistake on the B rows?

If I understand correctly, you can do it like this:

Do a 'Group By' with only 'All Rows'

Then add a custom Column using Table.RowCount on the column that the previous step created.

Expand the rows. That's it.

jgeddes
Super User
Super User

Table.AddColumn(#"previousStep", "Count of Items", each List.Count(Table.SelectRows(#"previousStep", (x) => x[Item] = "A")[Item]))

gets you...

jgeddes_0-1671724355810.png

Table.AddColumn(#"Changed Type", "Count of Items", each List.Count(Table.SelectRows(#"Changed Type", (x) => [Item] = x[Item])[Item]))

gets you...

jgeddes_1-1671724418053.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Anonymous
Not applicable

Unfortunately this does not work. Below is the formula Im using

= Table.AddColumn(#"Added Unit", "Count of Items", each List.Count(Table.SelectRows(#"Added Unit", (x) => [a.itm_nbr]=[a.itm)[a.itm]))

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.