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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
EWBWEBB
Helper III
Helper III

MAX Date date not working in variable

I have 2 tables, one which contains all my people information the other table contains their sick days and reasons.

 

StaffAbsence contains the following

Absence Key, Date, PersonRef, Period

 

A People Table where the list repeats every period for the employees this is laid out as follows

AbsenceKey,PersRef,Period,StartDate,LeaveDate,FirstDateofPeriod,LastDayofPeriod

 

What I would like to do is count all sickness days from the staff absence table which are in the period. However there are some instances where the person has a logged days sickness after there leave date.

 

So I want to count all sickness days in the period unless there is a leave date then I want to count to the leave date or period end date whichever is sooner.

 

This is my dax but it doesn't seem to be registering the <= and appears that this is being overrules somewhere.

 

SickeDays = 
VAR StartDate = MINX(STAFFPERIODIC,STAFFPERIODIC[First Date of Period])
VAR LeaveDate = MAXX(STAFFPERIODIC,STAFFPERIODIC[LEAVE_DATE])
VAR PeriodEnd = MAXX(STAFFPERIODIC,STAFFPERIODIC[Last Day of Period])

VAR MaxDate = IF(LeaveDate < PeriodEnd, LeaveDate, PeriodEnd)

VAR Result = 

CALCULATE(
	COUNTROWS(STAFFABSENCE),
			FILTER(STAFFABSENCE,STAFFABSENCE[DATE] >= StartDate &&
			STAFFABSENCE[DATE] <= MaxDate || LeaveDate = BLANK()
		)
		)




RETURN
Result
2 REPLIES 2
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

@lbendlin - thank you.


These two tables would be joined on the absence key. 
Absence

AbsenceKeyDatePersonRefPeriod
123452022-1128/10/2022123452022-11
123452022-1129/10/2022123452022-11
123452022-1130/10/2022123452022-11
123452022-1131/10/2022123452022-11
123452022-1101/11/2022123452022-11
123452022-1102/11/2022123452022-11
123452022-1103/11/2022123452022-11
123452022-1104/11/2022123452022-11
123452022-1105/11/2022123452022-11
123452022-1106/11/2022123452022-11
123452022-1107/11/2022123452022-11
123452022-1108/11/2022123452022-11
123452022-1109/11/2022123452022-11
123452022-1110/11/2022123452022-11
123452022-1111/11/2022123452022-11
123452022-1112/11/2022123452022-11
101112022-1128/10/2022101112022-11
101112022-1129/10/2022101112022-11
101112022-1130/10/2022101112022-11
101112022-1131/10/2022101112022-11
101112022-1101/11/2022101112022-11
101112022-1102/11/2022101112022-11
101112022-1103/11/2022101112022-11
101112022-1104/11/2022101112022-11
101112022-1105/11/2022101112022-11
101112022-1106/11/2022101112022-11
101112022-1107/11/2022101112022-11
101112022-1108/11/2022101112022-11
101112022-1109/11/2022101112022-11
101112022-1110/11/2022101112022-11
101112022-1111/11/2022101112022-11
101112022-1112/11/2022101112022-11
101112022-1015/10/2022101112022-10
101112022-1014/10/2022101112022-10
101112022-1013/10/2022101112022-10
101112022-1012/10/2022101112022-10
101112022-1011/10/2022101112022-10
123452022-1015/10/2022123452022-10
123452022-1014/10/2022123452022-10
123452022-1013/10/2022123452022-10
123452022-1012/10/2022123452022-10
123452022-1011/10/2022123452022-10

 

People

AbsenceKeyPersRefPeriodStartDateLeaveDateFirstDateofPeriodLastDayofPeriod
123452022-11123452022-1101/01/200011/12/202216/10/202212/12/2022
101112022-11101112022-1101/01/2000 16/10/202212/12/2022
101112022-10101112022-1001/01/2000 18/09/202215/10/2022
123452022-10123452022-1001/01/200011/12/202218/09/202215/10/2022


The output I would expect would be:

 

In Period 2022-10
12345 - would count 5 days

10111 - would count 5 days

 

In Period 2022-11
12345 - Would count 15 days (with the 12/11/2022 not being counted as it is after the leave date)

10111 - Would be 16 days (Counting the 12/11/2022 as they do not have a leave date)

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.