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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Katiek
Helper II
Helper II

Custom Column to count how many times the ID with the same date appears

 

Hi

 

I'm new to Power Query and Power BI. 

 

I'm trying to figure out in my table (Controldata2023tbl) how many times the ID shows up with the same Date. This is an example with 2 criteria, sometimes i have 3 criteria. In excel I used to do this with the Countifs formula, I would appreciate any help with how to do this in Power Query.

Many thanks in advance 🙂

 

Date               ID   Count

26.07.2023h111
26.07.2023h112
27.07.2023h111
28.07.2023h331
28.07.2023h332
28.07.2023h333
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Katiek ,

 

1. add a index column:

vcgaomsft_0-1690526948126.png

 

2. add a custom column:

vcgaomsft_1-1690526984990.png

Output:

vcgaomsft_2-1690527013895.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLTMzDXMzIwMlbSUTI0VIrVwSFmjkXMAknM2Jh4sVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, ID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"ID", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Count", each Table.RowCount(Table.SelectRows(#"Added Index", (x)=>x[Date]=[Date] and x[ID]=[ID] and x[Index]<=[Index]))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Katiek ,

 

1. add a index column:

vcgaomsft_0-1690526948126.png

 

2. add a custom column:

vcgaomsft_1-1690526984990.png

Output:

vcgaomsft_2-1690527013895.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLTMzDXMzIwMlbSUTI0VIrVwSFmjkXMAknM2Jh4sVgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, ID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"ID", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Count", each Table.RowCount(Table.SelectRows(#"Added Index", (x)=>x[Date]=[Date] and x[ID]=[ID] and x[Index]<=[Index]))),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Hi @Anonymous 

 

Thank you, you are a legend! It worked!!!

 

Thanks so much!

Hi @Anonymous 

 

Thanks so much for your solution. I'm going to give it a go now!

Syndicate_Admin
Administrator
Administrator

Hi,

 

 One solution would be to duplicate the first Query, group by criteria with a count then merge back in to original data...

 

There probably is a clever way to do this in a single step but unsure how that would affect performance. This way you can add as many criteria as you like as well.

 

Thanks,

Hi @Syndicate_Admin 

 

Thank you for your suggestion. 

Katiek
Helper II
Helper II

Sorry my example didn't upload properly. There are 3 columns Date, ID and count

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.