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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.