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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JānisB
Frequent Visitor

Dynamical categories and count of rows by categories on date

I have a DateTable and a fact table Table1:

EmployeeID | StartDate | EndDate

Employee1 | 2018-03-18 | 2025-04-25

Employee2 | 2019-04-20 | null

...

 

The result should look like:

JnisB_0-1748500317593.png

 

0-5, 6-10, 11-15, ... are groups of work experience (full years). If work experience is 5,9, then 5 full years.

The amounts are counts of employees (actives).

It is necessary to filter those data on date, for example on 2025-03-31 (could be year and month).

How to make this vizualisation? How to make dynamical count of employees by dynamical groups of work experience?

For example:

Employee1 - on 2025-03-31 should be in group 6-10, but on 2025-04-30 is not in the report because EndDate 2025-04-25

Employee2 - on 2025-03-31 should be in group 0-5, but on 2025-04-30 should be in group 6-10

 

1 ACCEPTED SOLUTION
techies
Super User
Super User

Hi @JānisB you can try this by creating a disconnected table for experience groups (e.g., 0–5, 6–10, etc.). Then use the following measure to count employees in each group, based on the selected reporting date

 

Employees in Bucket =
VAR SelectedDate = MAX('Date'[Date])
VAR MinYOS = MIN('Experience Groups'[MinYears])
VAR MaxYOS = MAX('Experience Groups'[MaxYears])
RETURN
CALCULATE (
    COUNTROWS (Table2),
    FILTER (
        Table2,
        Table2[StartDate] <= SelectedDate &&
        (ISBLANK(Table2[EndDate]) || Table2[EndDate] >= SelectedDate) &&
        VAR YOS = DATEDIFF(Table2[StartDate], SelectedDate, YEAR)
        RETURN YOS >= MinYOS && YOS <= MaxYOS
    )
)
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

View solution in original post

3 REPLIES 3
v-sgandrathi
Community Support
Community Support

Hi @JānisB,

 

Has your issue been resolved?If the response provided by the community member addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

If yes, kindly accept the useful reply as a solution and give us Kudos. It would be appreciated.

 

Thank you for your understanding!

techies
Super User
Super User

Hi @JānisB you can try this by creating a disconnected table for experience groups (e.g., 0–5, 6–10, etc.). Then use the following measure to count employees in each group, based on the selected reporting date

 

Employees in Bucket =
VAR SelectedDate = MAX('Date'[Date])
VAR MinYOS = MIN('Experience Groups'[MinYears])
VAR MaxYOS = MAX('Experience Groups'[MaxYears])
RETURN
CALCULATE (
    COUNTROWS (Table2),
    FILTER (
        Table2,
        Table2[StartDate] <= SelectedDate &&
        (ISBLANK(Table2[EndDate]) || Table2[EndDate] >= SelectedDate) &&
        VAR YOS = DATEDIFF(Table2[StartDate], SelectedDate, YEAR)
        RETURN YOS >= MinYOS && YOS <= MaxYOS
    )
)
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978
bhanu_gautam
Super User
Super User

@JānisB 

If you don't already have a Date Table, you can create one usingDAX
DateTable =
ADDCOLUMNS (
CALENDAR (DATE(2018, 1, 1), DATE(2025, 12, 31)),
"Year", YEAR([Date]),
"Month", MONTH([Date]),
"YearMonth", FORMAT([Date], "YYYY-MM")

 

Add two calculated columns to your Table1 to calculate the work experience in full years as of a given date.

StartYear = YEAR([StartDate])
EndYear = IF(ISBLANK([EndDate]), YEAR(TODAY()), YEAR([EndDate]))

 

Create a measure to calculate the work experience in full years as of the selected date.

WorkExperience =
VAR SelectedDate = MAX(DateTable[Date])
VAR EndDate = IF(ISBLANK(SELECTEDVALUE(Table1[EndDate])), SelectedDate, SELECTEDVALUE(Table1[EndDate]))
VAR WorkExperienceYears = DATEDIFF(SELECTEDVALUE(Table1[StartDate]), EndDate, YEAR)
RETURN WorkExperienceYears

 

Create a measure to count the number of employees in each work experience group.

EmployeeCountByExperienceGroup =
VAR SelectedDate = MAX(DateTable[Date])
RETURN
SUMX (
VALUES(Table1[EmployeeID]),
VAR WorkExperienceYears =
DATEDIFF(
Table1[StartDate],
IF(ISBLANK(Table1[EndDate]), SelectedDate, Table1[EndDate]),
YEAR
)
RETURN
SWITCH(
TRUE(),
WorkExperienceYears >= 0 && WorkExperienceYears <= 5, 1,
WorkExperienceYears > 5 && WorkExperienceYears <= 10, 2,
WorkExperienceYears > 10 && WorkExperienceYears <= 15, 3,
WorkExperienceYears > 15 && WorkExperienceYears <= 20, 4,
WorkExperienceYears > 20 && WorkExperienceYears <= 25, 5,
WorkExperienceYears > 25 && WorkExperienceYears <= 28, 6,
0
)
)

 

Add a slicer to your report to select the date.
Create a table or matrix visualization.
Add the work experience groups and the measure EmployeeCountByExperienceGroup to the visualization.




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

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.