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! Learn more

Reply
ubaid2001
Frequent Visitor

Count of Employees Based On Dynamic Age

I have Employees data in Power BI to calculate the count of employees by age group, I have created measure to calculate the age dynamically based on selected date against each employee ID

 

Age = DATEDIFF(MAX('fact_employee_history'[DOB]), MAX(dim_calendar[Date]), YEAR)
 
and then I have calculated the age group using this dax

AgeGroup =
VAR Age = [Age]
RETURN
    SWITCH(
        TRUE(),
        Age <= 30, "18-30",
        Age >= 31 && Age <= 40, "31-40",
        Age >= 41 && Age <= 50, "41-50",
        Age >= 51 && Age <= 60, "51-60",
        Age > 60, "60 above (other)",
        BLANK()
    ).
 

ubaid2001_0-1700473744858.png

Now I want to get the count of employees for each group instead of each Employee ID.

 

The final output will look like this

ubaid2001_1-1700474316260.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ubaid2001 ,

Please try:

Count = 
VAR _table = SUMMARIZE('Table','Table'[EmployeeID],"group",[AgeGroup])
VAR _cur_age_group = MAX('Age Groups'[Age Groups])
VAR _result = COUNTROWS(FILTER(_table,[group]=_cur_age_group))
RETURN
_result

 

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 -- China Power BI User Group

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi @ubaid2001 ,

Please create a new table like:

vcgaomsft_0-1700634819721.png

And a new measure like:

Count = 
VAR _table = SUMMARIZE('Table','Table'[EmployeeID],'Table'[Age],"group",[AgeGroup])
VAR _cur_age_group = MAX('Age Groups'[Age Groups])
VAR _result = COUNTROWS(FILTER(_table,[group]=_cur_age_group))
RETURN
_result

Output:

vcgaomsft_1-1700634861171.png

The result returned by the measure is dynamically calculated, which should work.

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 -- China Power BI User Group

Hi,

 

I have Employee ID in table, but age and age group both are measures, can you please help me with that.

 

Age Measure = DATEDIFF(MAX('fact_employee_history'[DOB]), MAX(dim_calendar[Date]), YEAR)

 

AgeGroup Measure =
VAR Age = [Age]
RETURN
    SWITCH(
        TRUE(),
        Age <= 30"18-30",
        Age >= 31 && Age <= 40"31-40",
        Age >= 41 && Age <= 50"41-50",
        Age >= 51 && Age <= 60"51-60",
        Age > 60"60 above (other)",
        BLANK()
    ).

 

Thanks

Anonymous
Not applicable

Hi @ubaid2001 ,

Please try:

Count = 
VAR _table = SUMMARIZE('Table','Table'[EmployeeID],"group",[AgeGroup])
VAR _cur_age_group = MAX('Age Groups'[Age Groups])
VAR _result = COUNTROWS(FILTER(_table,[group]=_cur_age_group))
RETURN
_result

 

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 -- China Power BI User Group

Uzi2019
Super User
Super User

Hi @ubaid2001 
You can simply take that column twice (age group) and set other age group to count like below. In my case sorting is my calculated column.

 

Uzi2019_0-1700475421322.png

 

I hope i answered your question!

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

I am not able to get the count of Age Group measure

ubaid2001_0-1700476789840.png

 

Hi @ubaid2001 
Please calculate the Age group in Column not measure.

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Once I am calculating it in column then it is not changing the group based on age dynamically.

Age measure is calculating the age dynamically based on selected date.

Ahmedx
Super User
Super User

You'll create a calculated column based on your measure. and then just create a new measure using DISTINCTCOUNT

can you please explain your solution in detail.

Thanks

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.

Top Solution Authors