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

Measures: Calculate difference between dates split per month

Hi All, 

 

I have a table such as: 

 

REFERENCE NUMBER REQUEST DATEVALIDATION DATECOMPLETION DATE
G_EUR_GBR_DSF00000028       22/11/201807/12/201817/12/2019

 

The result that i was expeting was 8 days for novemeber and 7 days for December for validation delay.  So I created a the following mesures :

 

 

.REC_Validation_Delay= 
VAR REQDate = VALUE( SELECTEDVALUE( RECRUITMENT[Request Date]) )
VAR VALDate = IF( ISBLANK(VALUE( SELECTEDVALUE( 'RECRUITMENT'[Validation Date] ) )),Today(),VALUE( SELECTEDVALUE( RECRUITMENT[Validation Date] ) ))
VAR MinDateInContext = VALUE( MIN( 'calendar'[Date] ) )
VAR MaxDateInContext = VALUE( MAX( 'calendar'[Date] ) )
RETURN
IF( AND( REQDate < MinDateInContext, VALDate > MinDateInContext ) ,
        MIN( VALDate, MaxDateInContext ) - MinDateInContext ,
            IF( AND( AND( REQDate > MinDateInContext, REQDate < MaxDateInContext ), VALDate > MinDateInContext ),
                 MIN( VALDate, MaxDateInContext ) - REQDate , 
                   BLANK() ) )

 

 

 And a second mesure which returns the real value for the item but the average in the total 

 

 

Average_validation_Delay = 
AVERAGEX( 
    VALUES( RECRUITMENT[Reference Number] ),
        [.REC_Validation_Delay] )

 

 

 

When I put the average_validation_delay measure into a table/matrix, it's returns the correct figure for NOV but no blank values for DEC and the total correct 15 days.

 

validation delay.jpg

 

 

I am also facing issue with another measure that i have used the same code just change the start date as validation and end date as completion date to calculat time to fill: 

 

 

.REC_Time_to_fill = 
VAR REQDate = VALUE( SELECTEDVALUE( RECRUITMENT[Validation Date] ) )
VAR VALDate = IF( ISBLANK(VALUE( SELECTEDVALUE( RECRUITMENT[Completion Date] ) )),Today(),VALUE( SELECTEDVALUE( RECRUITMENT[Completion Date] ) ))
VAR MinDateInContext = VALUE( MIN( 'calendar'[Date] ) )
VAR MaxDateInContext = VALUE( MAX( 'calendar'[Date] ) )
RETURN
IF( AND( REQDate < MinDateInContext, VALDate > MinDateInContext ) ,
        MIN( VALDate, MaxDateInContext ) - MinDateInContext ,
            IF( AND( AND( REQDate > MinDateInContext, REQDate < MaxDateInContext ), VALDate > MinDateInContext ),
                 MIN( VALDate, MaxDateInContext ) - REQDate , 
                   BLANK() ) )
REC - Time to Hire (Avg) = 
AVERAGEX( 
    VALUES( RECRUITMENT[Reference Number] ),
        [.REC_Time_to_fill] )

 

 

 

average.jpg

 

Any clue what is wrong ? 

the relationship between the recrtuiment table and calendar date has 3 dates interfaces inactive: 

interface.jpg

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , this file has split of dates on daily range. check if this can help

https://www.dropbox.com/s/bqbei7b8qbq5xez/leavebetweendates.pbix?dl=0

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , this file has split of dates on daily range. check if this can help

https://www.dropbox.com/s/bqbei7b8qbq5xez/leavebetweendates.pbix?dl=0

Anonymous
Not applicable

Thanks a lot 🙂

 

I worked properly and faster than the measure that i create initially. 

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.