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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Count only once in a group

Hello all,

Can you please suggest how I can acheive the below requirement.

My data set is like below. It has 'ID' and 'Years' fields. One ID may be present in one or more 'Years' group but I want to count 'ID' only in the first group its present. The group order is  '0-2','3-5' and '6-10'.

For example ID 1 is present in '0-2' and '3-5' group but it should only be counted in first group i.e '0-2'. 

 

IDYears
10-2
20-2
30-2
40-2
13-5
23-5
53-5
63-5
46-10
56-10
76-10

 

Below is the result I am looking for:  

 

Result 
YearsCount
0-24
3-52
6-101

 

Let me know if I am not clear. Thank you.

 

10 REPLIES 10
Stachu
Community Champion
Community Champion

so you only want to count first occurence of the particular ID as sorted per Years?



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

@Stachu yes please. 

hi, @Anonymous

If you want to filter the result, you could just improve the formula of  .

First, you must add a rank column for Years column.

Rank = RANKX( table1, Table1[Years], , ASC, Dense)

Second, Try this measure

Number of Ids = 
VAR t = CALCULATETABLE( VALUES( Table1[ID] ), FILTER( ALLSELECTED(Table1), Table1[Rank] < MAX( Table1[Rank] ) ) )
RETURN
CALCULATE( COUNT( Table1[ID] ),EXCEPT( VALUES( Table1[ID] ), t ) )

Result:

2.JPG3.JPG

 

Best Regards,

Lin

 

 

 

 

 

 

 

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

@Anonymous did you tried the solution I provided? Any issue ?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k

 

I tried the method that you suggested with full dataset but in some instances I am getting different counts. Any chance I can send dataset to you?

 

Thank you

@Anonymous sure we can look into this, share the dataset using onedrive/googledrive/dropbox etc and also point out in what case it doesnt work.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi, 

 

Here is the code for your issue.

 

let
Source = Excel.CurrentWorkbook(){[Name="Table14"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Years", type text}}),
#"Removed Duplicates" = Table.Distinct(#"Changed Type", {"ID"}),
#"Grouped Rows" = Table.Group(#"Removed Duplicates", {"Years"}, {{"Count", each Table.RowCount(_), type number}})
in
#"Grouped Rows"

 

Let me know, if you have any issue.

parry2k
Super User
Super User

@Anonymous your request is not clear, which values in 3-5 and 6-10 are getting counted?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k,

 

In '3-5 Years' group ID's 5 and 6 has to be counted because 1 and 2 are already counted in 'Years 0-2' group.

 

And in 'Years 6-10' group ID, only 7 has to be counted as 4 is already counted in 'Years 0-2' group and 5 is counted in '3-5' group. 

 

Please let me know if I am not clear. 

@Anonymous got it, try this

 

first add a column to assign id to each year group, I used Rank for this

 

Rank = RANKX( table1, Table1[Years], , ASC, Dense)

now add a measures to count IDs

 

Number of Ids = 
VAR t = CALCULATETABLE( VALUES( Table1[ID] ), FILTER( ALL(TAble1), Table1[Rank] < MAX( Table1[Rank] ) ) )
RETURN
CALCULATE( COUNT( Table1[ID] ),EXCEPT( VALUES( Table1[ID] ), t ) )

drop a table visual and add years and "number of ids" measure to this table, and you will get the result.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.