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
apoje
Helper II
Helper II

Custom Column - that counts distinct occurrences of an ID

Hi,

 

I have a dataset where I would benefit greatly with a helper column to see if the order has more items than one in an order. One row means one item - and I have an order ID, if there are more items in an order there are multiple rows with identical order IDs.

 

Desired result:

Order.IDItem.idQuantityHelper.Column.Count
1182612311
1182712322
1182712512
1182812821
1182912413
1182912353
1182914133
1183012311

 

 

I would appreciate if anyone can help me how to compute this Helper column. 

 

Thanks!

Andraz

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @apoje ,

 

You can use variable and list to count the ocurrence of each value, like:

let _orderId = [Order.ID] in
List.Count(List.Select(#"Changed Type"[Order.ID], each _ = _orderId))

 

Capture.PNG



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

Proud to be a Super User!



View solution in original post

6 REPLIES 6
camargos88
Community Champion
Community Champion

Hi @apoje ,

 

You can use variable and list to count the ocurrence of each value, like:

let _orderId = [Order.ID] in
List.Count(List.Select(#"Changed Type"[Order.ID], each _ = _orderId))

 

Capture.PNG



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

Proud to be a Super User!



@camargos88  Nice.  How does this perform for large tables?

Hi @lbendlin ,

 

I haven't tested it with a large database.

However I believe once it's a list, shouldn't have a heavy impact on it.

But it worths a test.



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

Proud to be a Super User!



lbendlin
Super User
Super User

do you want that in Power Query or in DAX?

@lbendlin  PowerQuery if possible 🙂

This is one example how to do it in Power Query.  If you have a large table then you might want to throw in a Table.Buffer

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjS0MDJT0lEyNDIGkWAcqwMRN4eLG4ExqrgpVD1C3AIsbgFVjzDHEixuAlVvjCYOMt8UU9wEohZJ3NgA3Z2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Order.ID = _t, Item.id = _t, Quantity = _t, Helper.Column.Count = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Order.ID", Int64.Type}, {"Item.id", Int64.Type}, {"Quantity", Int64.Type}, {"Helper.Column.Count", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Order.ID"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    Merged = Table.AddColumn(#"Changed Type","Join",(k)=> Table.SelectRows(#"Grouped Rows",each([Order.ID]=k[Order.ID]))),
    #"Expanded Join" = Table.ExpandTableColumn(Merged, "Join", {"Count"}, {"Count"})
in
    #"Expanded Join"

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.

Top Solution Authors