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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
metcala
Helper III
Helper III

Total time a post has been vacant between dates

Hi

 

I am looking to create a DAX measure to calculate the total amount of time a post has been vacant between two dates and another measure to count the instances of vacancy (recruitment campaigns).

 

All Occupant IDs start with a number and all Vacancy IDs start with V.

 

The data structure certainly is not ideal but unfortunately this is something I don't have control of and can not change.

 

Data Structure

 

Role IDDivisionGradeDisciplineOccupant ID/Vacancy IDStart DateEnd Date

1001

A1.1Sales100011/1/2030/6/21

1001

A1.1SalesV00101/7/2130/9/21

1001

A1.1Sales100101/10/21 
1002B1.3Support100021/1/2031/12/20
1002B1.3SupportV00021/1/2131/1/21
1002B1.3Support100031/2/2131/8/21
1002B1.3SupportV00121/9/2130/9/21
1002B1.3Support100151/10/21 

 

Expected Outcome

 

Date filter 1/1/20 to 30/9/21

 

Role IDVacant DaysVacant Instances
1001921
1002612

 

Have been struggling with this one and any help would be very much appreciated!

 

Thanks in advance!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @metcala 

Please refer to attached sample file with the proposed solution

1.png

Vacant Days = 
VAR MinDate = MIN ( 'Date'[Date] )
VAR MaxDate = MAX ( 'Date'[Date] )
RETURN
    SUMX (
        FILTER ( 
            'Table',
            ISERROR ( VALUE ( 'Table'[Occupant ID/Vacancy ID] ) )
        ),
        DATEDIFF (
            MAX ( 'Table'[Start Date], MinDate ),
            MIN ( COALESCE ( 'Table'[End Date], TODAY ( ) ), MaxDate ),
            DAY
        ) + 1
    )
Vacant Instances = 
COUNTROWS ( 
    FILTER ( 
        'Table',
        ISERROR ( VALUE ( 'Table'[Occupant ID/Vacancy ID] ) )
    )
)

View solution in original post

3 REPLIES 3
eliasayyy
Memorable Member
Memorable Member

hello @metcala 

use 3 measures

 

Condition = 
IF( LEFT(MAX('Table'[Occupant ID/Vacancy ID]),1) = "V" , "Yes" , "No")

 

 

 

Count = 
COUNTROWS(FILTER('Table',[Condition] = "Yes"))

 

 

 

Date Diff = SUMX(FILTER('Table',[Condition] = "Yes"),DATEDIFF( 'Table'[Start Date] , 'Table'[End Date] ,DAY) + 1 )

 



annonymous1999_0-1686915555506.png

 

 

tamerj1
Super User
Super User

Hi @metcala 

Please refer to attached sample file with the proposed solution

1.png

Vacant Days = 
VAR MinDate = MIN ( 'Date'[Date] )
VAR MaxDate = MAX ( 'Date'[Date] )
RETURN
    SUMX (
        FILTER ( 
            'Table',
            ISERROR ( VALUE ( 'Table'[Occupant ID/Vacancy ID] ) )
        ),
        DATEDIFF (
            MAX ( 'Table'[Start Date], MinDate ),
            MIN ( COALESCE ( 'Table'[End Date], TODAY ( ) ), MaxDate ),
            DAY
        ) + 1
    )
Vacant Instances = 
COUNTROWS ( 
    FILTER ( 
        'Table',
        ISERROR ( VALUE ( 'Table'[Occupant ID/Vacancy ID] ) )
    )
)

Thanks so much for the prompt response. It worked perfectly!!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

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.