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
casabs
Frequent Visitor

How To Get Multiple Min and Max Occurences in Dax

Hi

 

I am trying to return periods of holiday for some colleagues in my organisation but can't find a way in Dax to achive this. Equally if it can be acheived in SQL, that is how the data is currently stored

Desired Result:

Colleague 123: Blank/No Holiday

Colleague 456: 02/02/2024 - 03/02/2024

Colleague 789: 02/02/2024 - 03/02/2024

                         06/02/2024 - 08/02/2024

 

The table is currently vertically strucutured with a combined Key of colleague ID and Date

 

Example below:

DateColleague IDHoliday
01/02/20241230
02/02/20241230
03/02/20241230
04/02/20241230
05/02/20241230
06/02/20241230
07/02/20241230
08/02/20241230
01/02/20244560
02/02/20244567
03/02/20244567
04/02/20244560
05/02/20244560
06/02/20244560
07/02/20244560
08/02/20244560
01/02/20247890
02/02/20247897
03/02/20247897
04/02/20247890
05/02/20247890
06/02/20247897
07/02/20247897
08/02/20247897

 

 

3 REPLIES 3
rbriga
Impactful Individual
Impactful Individual

Alright, I mistook the direction you need to go. 

Let's try more SQL, based on this Stack Overflow post

CASE HOLIDAY
WHEN 0 THEN NULL
ELSE
MAX(CASE WHEN HOLIDAY = 0 THEN DATEADD(DAY,1,DATE) END) OVER (PARTITION BY COLLEAGUE_ID ORDER BY DATE by date) 
END as VACATION START,
CASE HOLIDAY
WHEN 0 THEN NULL
ELSE
MIN(CASE WHEN HOLIDAY = 0 THEN DATEADD(DAY,-1,DATE) END) OVER (PARTITION BY COLLEAGUE_ID ORDER BY DATE by date DESC) 
END as VACATION END,

Does that create the desired start and end dates?

If so, you can then use that as a temporary table (WITH T AS) and SELECT DISTINCT

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!
rbriga
Impactful Individual
Impactful Individual

Let's solve this in SQL- like you've hinted, it's best to push the calculations to the source.

I'm assuming you have a date table [DATE_TABLE] with the date field [DATE_VALUE].

Also, you have the table [VACATION_TABLE] with VACATION_START and VACATION_END.

Now:

SELECT 
	VACATION.Colleague_ID,
	DATES.DATE_VALUE,
	'1'	AS "Vacation Day"
FROM VACATION_TABLE VACATION
INNER JOIN DATE_TABLE DATES
ON DATES.DATE_VALUE >= DATE(VACATION.VACATION_START) AND DATES.DATE_VALUE <=DATE(VACATION.VACATION_END)

(If VACATION_START and VACATION_END are already dates, you don't need DATE() )

 

So if colleague 123 was out between  2024-01-04 and 2024-01-11, this will return:

 

ID  DATE_VALUE Vacation Day

1232024-01-041
1232024-01-051
1232024-01-061
1232024-01-071
1232024-01-081
1232024-01-091
1232024-01-101
1232024-01-111

Does this work?

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!
casabs
Frequent Visitor

Hey thanks for the reply

 

I don't have the vacation start and end date in that format, and that is part of the challenge. The table has a date column, and a vacation column.

 

In the vacation column the value is 0 for days with no vacation and then a positive integer (representing number of hours) for days when holiday is booked. 

the problem with min(date) and max(date) where holiday > 0 will only give me one date for min and max, not each occurence

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.