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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! 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
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.