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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate Count Between Two Dates - Incorrect on Higher Level of Date Hierarchy

Hi all,

 

I am trying to create a report which shows number of employee terminations during parental leave.

My model is below.

 

image.png

 

 

 

 

Employee and TimeOffRequest SF tables are joined by EmployeeID, and there is no physical relationship on CalDate table (it is also marked as Date table).

In the report, there are other visuals which rely on CalDate table, but I only use one slicer based on CalDate[Date] (hence no physical relationship on the model).

 

This is the DAX formula that I use to create the measure:

 

 

TerminationCountDuringLeave = 
    CALCULATE(
                DISTINCTCOUNT(Employee[SFUserID]),           
                FILTER(TimeOffRequestSF, 
                       TimeOffRequestSF[LeaveStartDate] <= MAX(CalDate[CalDate])
                       && TimeOffRequestSF[LeaveEndDate] >= MIN(CalDate[CalDate])
                ),
               TREATAS(VALUES(CalDate[CalDate]), Employee[TerminationDate])             
    )

This seems to work fine / giving the correct result on Date level, but when I go to Month level, it is not showing correct result.

 

For example, as you can see in the pic below, there is no data for February 2019 when the visual showing date-level.

 

image.png

However, when I drill-down to Month level, it is showing some records for Feb 2019 (and other months which not meant to be there).

image.png


I created a drillthrough page to see the actual records and found the following for Feb 2019.

image.png

 

So, I think because of the following condition in the DAX measure, when the visual is in Month level, for the first record it says: LeaveEndDate = 6 Feb 2019 >= Min date of february 2019 (= 1 Feb 2019), which is true.

&& TimeOffRequestSF[LeaveEndDate] >= MIN(CalDate[CalDate])

I dont want this to be included (and the second record also) because the termination date is outside LeaveStart and LeaveEnd dates.

 

How can I achieve the correct results regardless the visual is showing date-level or month-level?

 

Thanks

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Change the direction between table "Employee" and "TimeOffRequestSF" from single to both and check if the result is as your expected result.

Capture.PNG 

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Thanks for the reply @v-yuta-msft . Unfortunately, changing to Both direction does not change anything. Still giving the same wrong result. 😞

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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