Forum Discussion

EWBWEBB's avatar
EWBWEBB
Icon for Helper III rankHelper III
3 years ago

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

    • EWBWEBB's avatar
      EWBWEBB
      Icon for Helper III rankHelper III

      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)