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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

Difference between two dates in a measure

Hello everyone!

I have the following measure:

MaxDate = CALCULATE(MAX(Mastercalendar[Date]),filter(Mastercalendar,Mastercalendar[Weekday]<=5))

 

The objective is to give me the maximum date of the week selected on the slicer stopping Friday (I am not interested on Saturday/Sunday)

 

Occurences =CALCULATE(COUNT(uvw_GBS_KPIs_HR_v2[hrc_number]),FILTER(ALL(Mastercalendar),Mastercalendar[Date]<=[MaxDate]))

 

This way I get all the occurences until the maximum dates

 

My objective is to make a count of occurences that MaxDate - opened_at is less than 15 days and it produces 

a % that seems right.

 

Occurences_15 = CALCULATE([Occurences]
,FILTER(uvw_GBS_KPIs_HR_v2,[MaxDate]-uvw_GBS_KPIs_HR_v2[opened_at]<=15))/[Occurences]

My problem is when I use the following formula:

Occurences_15_30 = (CALCULATE([Occurences]
,FILTER(uvw_GBS_KPIs_HR_v2,([MaxDate]-uvw_GBS_KPIs_HR_v2[opened_at])*1>
15&&([MaxDate]-uvw_GBS_KPIs_HR_v2[_opened_at])*1<=30))
/[Occurences])+0

I used the *1 and also without it, but when I put the conditon between two dates I always have a 0% percentage.
What mistake am I doing here? 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

The error was I needed to clear some other filters from the mastercalendar.
This works:

CALCULATE(CALCULATE([occurrences],
FILTER(Table,([MaxDate]-uvw_GBS_KPIs_HR_v2[opened_at])*1>15&&
([MaxDate]-Table[LT_opened_at])*1<=30)),ALL(Mastercalendar))
/[occurrences]+0

View solution in original post

2 REPLIES 2
bizbi
Advocate I
Advocate I

Occurences_15 = CALCULATE([Occurences]
,FILTER(uvw_GBS_KPIs_HR_v2,[MaxDate]-uvw_GBS_KPIs_HR_v2[opened_at]<=15))/[Occurences]

 

Occurences_15_30 = (CALCULATE([Occurences]
,FILTER(uvw_GBS_KPIs_HR_v2,([MaxDate]-uvw_GBS_KPIs_HR_v2[opened_at])*1>15&&([MaxDate]-uvw_GBS_KPIs_HR_v2[_opened_at])*1<=30))/[Occurences])+0

 

These two red highlights are cancelling each other.

 

 

 

Anonymous
Not applicable

The error was I needed to clear some other filters from the mastercalendar.
This works:

CALCULATE(CALCULATE([occurrences],
FILTER(Table,([MaxDate]-uvw_GBS_KPIs_HR_v2[opened_at])*1>15&&
([MaxDate]-Table[LT_opened_at])*1<=30)),ALL(Mastercalendar))
/[occurrences]+0

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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