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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Learner86
Helper I
Helper I

Distinct count in custom column

Hi everybody,

 

I have a column with the name of customers, like this:

 

Costumer

A

A

B

C

C

D

E

F

F

 

Some names appear once and other names appear multiple times. How can I write a syntax in Power Query to compute distinct count values in new custom column?

 

Thank you very much for your proposed solutions.

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YGRTmDSGYl0AZOuYNINRsYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each let thiscustomer = [Customer] in Table.RowCount(Table.SelectRows(Source, each [Customer] = thiscustomer)), Int64.Type)
in
    #"Added Custom"

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@Learner86 , You can get in a table.

 

You can remove duplicate values. Or create a copy of the table and remove duplicate values.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak: Thank you for the solution. I want to keep the duplicate values. I want to have a new column like this:

 

Costumer Newcolumn

A                2

A                2

B                1

C                2

C                2

D                1

E                 1

F                 2

F                 2

Hi @Learner86 

 

In Power Query add t

ry this code:

1- in Applied steps click on "Insert Step After"

VahidDM_0-1630501068805.png

2- copy this code and past in the new step:

= Table.RemoveColumns(Table.ExpandTableColumn(Table.Group(Source, {"Costumer"}, {{"All Row", each _, type table [Costumer=nullable text]}, {"Count", each Table.RowCount(_), Int64.Type}}), "All Row", {"Costumer"},{"All Row"}),{"All Row"})

 

Output:

VahidDM_1-1630501228820.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Appreciate your Kudos VahidDM_2-1630501249465.png !!

 

 

**Whole M codes are as below (For your reference):

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclSK1YGRTmDSGYl0AZOuYNINRsYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Costumer = _t]),
    #"Removed Columns" = Table.RemoveColumns(Table.ExpandTableColumn(Table.Group(Source, {"Costumer"}, {{"All Row", each _, type table [Costumer=nullable text]}, {"Count", each Table.RowCount(_), Int64.Type}}), "All Row", {"Costumer"},{"All Row"}),{"All Row"})
in
    #"Removed Columns"

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.