- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Get Min and Max Date Based on Batch Number and Employee
Hi all,
As the subject suggests, I am trying to get the minimum and maximum date based on batch number and employee. My dataset contains every transaction an employee made. So an example of my dataset looks like this:
DATE | Employee ID | Batch Number | Task
10-Dec-2023 22:01:00 | 123456 | 000001 | Task A
10-Dec-2023 22:13:00 | 123456 | 000001 | Task B
10-Dec-2023 22:20:00 | 123456 | 000001 | Task C
10-Dec-2023 22:55:00 | 123456 | 000001 | Task D
11-Dec-2023 8:00:00 | 123456 | 000002 | Task A
11-Dec-2023 8:10:00 | 123456 | 000002 | Task B
11-Dec-2023 8:11:00 | 123456 | 000002 | Task C
11-Dec-2023 8:30:00 | 123456 | 000002 | Task D
One Employee can perform Tasks on several batches at different times
One Batch number has several Tasks, but only one Employee, which means, for example, Batch# 000002 can only be assigned to Employee ID# 123456
So, now im looking for the min and max date per Batch per Employee because i want to calculate the duration for an Employee to complete a Batch.
Taking the above dataset as example, I would expect something like this:
DATE | Employee ID | Batch Number | Task | Min Date | Max Date | Duration
10-Dec-2023 22:01:00 | 123456 | 000001 | Task A | 10-Dec-2023 22:01:00 | 10-Dec-2023 22:55:00 | 54 min
10-Dec-2023 22:13:00 | 123456 | 000001 | Task B | 10-Dec-2023 22:01:00 | 10-Dec-2023 22:55:00 | 54 min
10-Dec-2023 22:20:00 | 123456 | 000001 | Task C | 10-Dec-2023 22:01:00 | 10-Dec-2023 22:55:00 | 54 min
10-Dec-2023 22:55:00 | 123456 | 000001 | Task D | 10-Dec-2023 22:01:00 | 10-Dec-2023 22:55:00 | 54 min
11-Dec-2023 8:00:00 | 123456 | 000002 | Task A | 11-Dec-2023 8:00:00 | 11-Dec-2023 8:30:00 | 30 min
11-Dec-2023 8:10:00 | 123456 | 000002 | Task B | 11-Dec-2023 8:00:00 | 11-Dec-2023 8:30:00 | 30 min
11-Dec-2023 8:11:00 | 123456 | 000002 | Task C | 11-Dec-2023 8:00:00 | 11-Dec-2023 8:30:00 | 30 min
11-Dec-2023 8:30:00 | 123456 | 000002 | Task D | 11-Dec-2023 8:00:00 | 11-Dec-2023 8:30:00 | 30 min
I have tried to create calculated column using this in the query:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@junmin , I think task needs to be part of that
ColumnEarliestDate =
CALCULATE(
MIN('Table'[DATE]),
ALLEXCEPT('Table',
'Table'[Employee ID], 'Table'[Batch Number], 'Table'[Task])
)
ColumnLatestDate =
CALCULATE(
MAX('Table'[DATE]),
ALLEXCEPT('Table',
'Table'[Employee ID], 'Table'[Batch Number], 'Table'[Task])
)
ColumnDuration = DATEDIFF('Table'[ColumnEarliestDate], 'Table'[ColumnLatestDate], MINUTE)
better you to have measure with required columns in table visual. Same can work as measure
You can also consider earlier for column
Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8
Or Try measures like
MinDateWithTask =
CALCULATE(
MIN('Table'[DATE]),
ALLSELECTED('Table'),
'Table'[Employee ID] = MAX('Table'[Employee ID]),
'Table'[Batch Number] = MAX('Table'[Batch Number]),
'Table'[Task] = MAX('Table'[Task])
)
MaxDateWithTask =
CALCULATE(
MAX('Table'[DATE]),
ALLSELECTED('Table'),
'Table'[Employee ID] = MAX('Table'[Employee ID]),
'Table'[Batch Number] = MAX('Table'[Batch Number]),
'Table'[Task] = MAX('Table'[Task])
)
DurationWithTask =
DATEDIFF(
[MinDateWithTask],
[MaxDateWithTask],
MINUTE
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@junmin , I think task needs to be part of that
ColumnEarliestDate =
CALCULATE(
MIN('Table'[DATE]),
ALLEXCEPT('Table',
'Table'[Employee ID], 'Table'[Batch Number], 'Table'[Task])
)
ColumnLatestDate =
CALCULATE(
MAX('Table'[DATE]),
ALLEXCEPT('Table',
'Table'[Employee ID], 'Table'[Batch Number], 'Table'[Task])
)
ColumnDuration = DATEDIFF('Table'[ColumnEarliestDate], 'Table'[ColumnLatestDate], MINUTE)
better you to have measure with required columns in table visual. Same can work as measure
You can also consider earlier for column
Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8
Or Try measures like
MinDateWithTask =
CALCULATE(
MIN('Table'[DATE]),
ALLSELECTED('Table'),
'Table'[Employee ID] = MAX('Table'[Employee ID]),
'Table'[Batch Number] = MAX('Table'[Batch Number]),
'Table'[Task] = MAX('Table'[Task])
)
MaxDateWithTask =
CALCULATE(
MAX('Table'[DATE]),
ALLSELECTED('Table'),
'Table'[Employee ID] = MAX('Table'[Employee ID]),
'Table'[Batch Number] = MAX('Table'[Batch Number]),
'Table'[Task] = MAX('Table'[Task])
)
DurationWithTask =
DATEDIFF(
[MinDateWithTask],
[MaxDateWithTask],
MINUTE
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

hi amitchandak, thank you for your reply. May I pls know why I must include tasks as well? So, if I were to have other columns (besides the one i showed here), do I have to include all of them as well?
thank you.

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
03-21-2024 11:49 PM | |||
02-16-2024 11:37 PM | |||
Anonymous
| 05-03-2024 03:52 AM | ||
09-13-2018 03:53 PM | |||
03-21-2024 04:23 PM |
User | Count |
---|---|
85 | |
70 | |
68 | |
50 | |
32 |
User | Count |
---|---|
117 | |
100 | |
73 | |
65 | |
40 |