Forum Discussion

metcala's avatar
metcala
Icon for Helper III rankHelper III
2 years ago
Solved

Expected hours per day

Hi

 

I am currently looking to write a DAX measure that looks at the expected hours per day vs recorded hours.

 

Data structure

 

Date

Date table

 

Resource

IDNameRoleStart DateEnd DateFTE
      

 

Time Record

IDNameDateActivityHours
     

 

Names

Bridging table

 

 

Relationships

Date table is linked to Resource on start date and end date with inactive relationships

Date table linked to Time Record on date with active relationship

Time Record linked to Names with active relationship

Resource linked to Names with active relationship

 

 

Expected Outcome

 

 1/5/241/5/24

1/5/24

2/5/24

2/5/24

2/5/24

....

NameExpectedActualDifferenceExpectedActualDifference 
        

 

Expected hours is 8 hours * FTE but only applies to week days which I wasn't sure how to approach.

 

This is the measure I've written so far for Expected Hours but it isn't quite working and isn't accounting for week days. Not quite sure where to start with the difference yet either.

 

Expected Hours =
SUMX(
VALUES('Resource'[Name]),
CALCULATE(
SUMX('Resource',
IF('Resource'[Start Date]<=TODAY() && ISBLANK('Resource'[End Date] && 'Resource'[Start Date]<MAX('Date'[Date]),
'Resource'[FTE]*8,
IF(IF('Resource'[Start Date]<=TODAY() && 'Resource'[End Date]>TODAY() && 'Resource'[Start Date]<MAX('Date'[Date]),
'Resource'[FTE]*8,
0)
)
)
)
)

Any help would be very much appreciated! 

  • Anonymous's avatar
    Anonymous
    2 years ago

    lbendlin , thanks for your concern about this case, I have an addition to make to the content.

    Hi  metcala ,

     

    If by weekdays you mean Monday to Friday, you can add the following filter to the formula:

    NOT(WEEKDAY(MAX('Table'[Date]),2)) in {6,7}

    If by weekdays you mean not only Monday to Friday but also the rest of the holidays, you can first use Enter data to create a table to collect the holiday information and add the following filter to the formula:

    NOT(WEEKDAY(MAX('Table'[Date]),2)) in {6,7} && NOT(MAX('Table'[Date])) in SELECTCOLUMNS('Holidays_Table',"date",[Holidays])

    If it doesn't meet your expectations, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

     

    Best Regards,

    Liu Yang

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

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    lbendlin , thanks for your concern about this case, I have an addition to make to the content.

    Hi  metcala ,

     

    If by weekdays you mean Monday to Friday, you can add the following filter to the formula:

    NOT(WEEKDAY(MAX('Table'[Date]),2)) in {6,7}

    If by weekdays you mean not only Monday to Friday but also the rest of the holidays, you can first use Enter data to create a table to collect the holiday information and add the following filter to the formula:

    NOT(WEEKDAY(MAX('Table'[Date]),2)) in {6,7} && NOT(MAX('Table'[Date])) in SELECTCOLUMNS('Holidays_Table',"date",[Holidays])

    If it doesn't meet your expectations, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

     

    Best Regards,

    Liu Yang

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

  • Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

    Do not include sensitive information or anything not related to the issue or question.

    If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216

    Please show the expected outcome based on the sample data you provided.

    Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523