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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
bednarol
New Member

Count occurrence

I want to add a column and count how many times a certain Program Name occurs in column "Program" in table "Dimension". I tried to add custom column and following formula but get "COUNTX" not recognized.

 

=COUNTX(FILTER(EARLIER([Program])=[Program]),[Program])

 

Thanks!

 

1 ACCEPTED SOLUTION

Hi @bednarol 

In my first solution of the previous reply, i use "Group" function, but it would not change the data model, 

please note, i add two "operations",

one is "count"(count rows) based on "program" column, 

another is "all"(don't summarized), it means it would be the original columns.

Capture1.JPG

then i get two columns, one is "count", another is "all", 

in "all" column, there are all my original columns nested here,

i click on "expand" icon from the "all" column and select columns i need, i can get all original columns.

Capture2.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

7 REPLIES 7
v-juanli-msft
Community Support
Community Support

Hi @bednarol 

In Edit queries, you can group rows and add a count column.

Capture4.JPGCapture5.JPG

Or, create a calculated column in Data model view,

Capture6.JPG

 

Column = CALCULATE(COUNT('Table'[program]),ALLEXCEPT('Table','Table'[program]))

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Grouping is obvious but I do not want to do that because I need to keep the table ungroup for futher data manipulation. Using the calculated column in Desktop in a good idea but I cannot figure out how to do that in Excel Power Query. Maybe that is one of the limitation?

Hi @bednarol 

In my first solution of the previous reply, i use "Group" function, but it would not change the data model, 

please note, i add two "operations",

one is "count"(count rows) based on "program" column, 

another is "all"(don't summarized), it means it would be the original columns.

Capture1.JPG

then i get two columns, one is "count", another is "all", 

in "all" column, there are all my original columns nested here,

i click on "expand" icon from the "all" column and select columns i need, i can get all original columns.

Capture2.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

This is an awesome idea! I learnt something new today. Thank you!

VasTg
Memorable Member
Memorable Member

@bednarol 

 

Try this..

 

Column = COUNTX(FILTER(Dimension,EARLIER(Dimension[Program])=Dimension[Program]),Dimension[Program])

 

If this helps, accept it as a solution.

Kudos are nice too.

 

Connect on LinkedIn

I am getting "COUNTX' not recognized. I should make clear that I am trying to use Power Query in Excel, not Power BI Desktop since the user who will be using this does not have desktop. I tried to enable addins that seem to be relevant. Is it something that is not available in Power Query?

Hi @bednarol 

Your formula with "COUNTX' is a DAX formula, which is used in a measure or a calculated column in Power Pivot.

If you just use it in Power Query->Add a custom column, it should not work as default.

In Power Query, you can refer to my first solution in my previous reply.

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors