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
maclura
Resolver I
Resolver I

DAX: measure to calculate total available time in a selected period

Hi,

 

I am working on a report on technician utilisation.

I created several measures to perform time evaluations, which can be sliced by Date, Technician, Country, Activity, etc...

but there is a probem I don't know how to solve.

I try to explain

 

I have a time entries table like

TimeEntry.IdTech.IdDate StartActivityDuration
1a2022-01-01Holiday8
2b2022-01-01Holiday8
3c2022-01-01Office9
4d2022-01-01Office9
5a2022-01-02Travel1
6a2022-01-02Office6
7a2022-01-02Travel1
8b2022-01-02Travel1.5
9b2022-01-02Office6
10b2022-01-02Travel1.5

I have a related technician table like

Tech.IdCountryStandard Daily Working Time
aIceland8
bSlovakia9
cSingapore8
dPuerto Rico9

I have a calendar table like

DateWeekDayNumber
2022-01-015
2022-01-026
2022-01-030
2022-01-041
2022-01-052
2022-01-063
2022-01-074

I have a holiday calendar table like

Holiday CountryHoliday NameHoliday Date
ThailandNew Year's Day2022-01-01
FranceNew Year's Day2022-01-01
MexicoConstitution day2022-02-07

 

Now, I need to create a measure to calculate what is the technician's standard available working time in the selected period with all the other filters applied. 

 

The first challenge for me is to keep in count that Saturday and Sunday have "Standard Daily Working Time" = 0 as well Holiday days in the technician's country.

And the second challenge is that I need the sum of the standard available working time of one or all technicians or any subset of them.

 

For example, if the technician slicers in the report have 2 technicians selected (one based in Brazil and the other in Japan) and my time slicer have Q1 2021 selected, I would like to calculate what is the sum of the standard available time of the 2 technicians put together for Q1 2021. aka MyMeasure = (tech 1 std time + tech 2 std time) in Q1 2021.

 

Having this measure would allow me to perform many more evaluation on utilisation.

 

Thanks for any hint.

 

maclura

1 ACCEPTED SOLUTION

Hi @v-chenwuz-msft ,

My conclusion is that you can't do that with DAX, and if you can, it's not the best approach.

Thanks to this post and to the Karimkz's reply I concluded that you have to solve it in Power query M.

So I merged (leftouter) my calendar table with the technician table, and in this way I've got all the dates I need.

Then all the DAX calculations have become easy and clean and neat.

Thanks for all your support.

maclura

View solution in original post

4 REPLIES 4
PaulOlding
Solution Sage
Solution Sage

Hi @maclura 

Here's a measure to get total available working time.  It iterates the Technician table so will give you the result per technician and also in total.  There's an assumption that holidays in your Holiday Calendar are not on weekends.

Available Working Time = 
SUMX(
    Technician,
    VAR _Days = 
    CALCULATE(
        COUNTROWS('Calendar'),
        KEEPFILTERS('Calendar'[WeekDayNumber] < 5)
    )
    VAR _Country = Technician[Country]
    VAR _Holidays = 
    CALCULATE(
        COUNTROWS('Holiday Calendar'),
        TREATAS(VALUES('Calendar'[Date]), 'Holiday Calendar'[Holiday Date]),
        'Holiday Calendar'[Holiday Country] = _Country
    )
    VAR _Result = (_Days - _Holidays) * Technician[Standard Daily Working Time]
    RETURN
        _Result
)

 

Thanks @PaulOlding for your suggestion, but it doesn't work and it's my fault, because I didn't provide enough context.
We can't calculate the total available working time iterating the Technician table, because in this way my slicers on the Time entries table have no effect.

In particular, I have a filter to investigate what happens in working days compared to not-working days.
In fact, the Time entries table, with more context, looks like:

TimeEntry.IdTech.IdDate StartActivityDurationIs Not WorkingStandard Daily Time
1a2022-01-01Holiday8TRUE0
2b2022-01-01Holiday8TRUE0
3c2022-01-01Office9FALSE8
4d2022-01-01Office9FALSE9
5a2022-01-02Travel1FALSE8
6a2022-01-02Office6FALSE8
7a2022-01-02Travel1FALSE8
8b2022-01-02Travel1.5FALSE9
9b2022-01-02Office6FALSE9
10b2022-01-02Travel1.5FALSE9

Now, the best I managed to calculate total available working time is whith this measure:

 

Time_Standard = 
SUMX(
    SUMMARIZE('Time Entry', 
        [Tech.Id],
        [Date Start],
        [Standard Daily Time]
    ),
    [Standard Daily Time]
)

 

But the issue is that, when there are days without time entries, that day is not counted. And I don't know how to address it.

Until now I tryed different approaches, but without any success.

One of them was to create a daily summary of the Time entries table and then crossjoin it with the calendar table with 

 

Daily Timesheet = SUMMARIZE(CROSSJOIN( 'Date', 'Time Entry' ), 
    [Date], 
    [Tech.Id]
)

 

Then adding new calculated columns for "Technician Country", "Is Not Working" and "Standard Time" with: 

 

TechCountry = RELATED(Technician[Tech Country])

Is Not Working = IF(
    RELATED('Date'[WeekDayNumber]) > 4 ||  //a day in the weekend
    SUMX('Holiday Dates', FIND([Date] & [TechCountry], 'Holiday Dates'[Holiday Date] & 'Holiday Dates'[HolidayCountry],,0)) > 0, //an holiday day in the technician country 
    TRUE, 
    FALSE
    )
Standard Time = IF([Is Not Working] = TRUE, 
    0,
    IF(
        ISBLANK(RELATED(Technician[Max Daily Hours])), 
        8, // We assume a standard 8 working hours per day
        RELATED(Technician[Max Daily Hours])
    )
)

 

And finally creating the missing columns through LOOKUP to the original time entries table, like e.g.

 

Documented Time = LOOKUPVALUE('Time Entry'[Daily Documented Time],'Time Entry'[Tech.Id],[Tech.Id],'Time Entry'[Date Start],[Date],0)

 

 The main issue with this approach is the size of the cross joined daily summary table and the fact that I have to work with columns and not with measures.

 

I hope this can clarify.

maclura

Hi 

 

I will try to solve your problem and I will update it here when I have results.

 

Best Regards

Community Support Team _ chenwu zhu

Hi @v-chenwuz-msft ,

My conclusion is that you can't do that with DAX, and if you can, it's not the best approach.

Thanks to this post and to the Karimkz's reply I concluded that you have to solve it in Power query M.

So I merged (leftouter) my calendar table with the technician table, and in this way I've got all the dates I need.

Then all the DAX calculations have become easy and clean and neat.

Thanks for all your support.

maclura

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.

Top Solution Authors