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
adriano321souza
Frequent Visitor

help with equation

Good afternoon,

I would like to adjust the equation below to the following case.

1. Calculate the start and end time of a process excluding holidays and weekend.

2. The weekend starts at 12AM on Saturday and runs until 00PM Sunday

3. I have the holidays column inside the calendar and the weekdays column

 

Minutes_Elapsed: = 
VAR startDatetime = 'Fact'[Data_Hora_Abert]
VAR endDatetime =
    IF (
        ISBLANK ( 'Fact'[Data_Hora_Fech] ) || 'Fact'[Data_Hora_Fech] < 'Fact'[Data_Hora_Abert], // WARNING: fix this to address blanks
        startDatetime,
        'Fact'[Data_Hora_Fech]
    ) 
VAR NormalRange = DATEDIFF( endDatetime, startDatetime, MINUTE )
VAR FilteredRange =
    FILTER (
        GENERATESERIES ( startDatetime, endDatetime, TIME ( 0, 1, 0 ) ),
        NOT WEEKDAY ( [Value] ) IN { 1 } // Sunday
            && NOT (  WEEKDAY ( [Value] ) IN { 7 } && HOUR ( [Value] ) >= 0 && HOUR ( [Value] ) < 12 ) // Saturday
            && NOT ( MONTH ( [Value] ) = 12 && DAY ( [Value] ) = 25 ) // Christmas example
    )

RETURN
    NormalRange - (NormalRange - COUNTROWS ( FilteredRange ) )

Arquivo PBIX

 

 

5 REPLIES 5
adriano321souza
Frequent Visitor

Good night,

I need to determine customer service time and for this, I must take into account the following items:

  1. Eliminate national holidays

  2. Eliminate the weekend from 12h on Saturday until 23:59:59 on Sunday.

Help!

Minutes_Elapsed: = 
VAR startDatetime = 'Fact'[Data_Hora_Abert]
VAR endDatetime =
    IF (
        ISBLANK ( 'Fact'[Data_Hora_Fech] ) || 'Fact'[Data_Hora_Fech] < 'Fact'[Data_Hora_Abert], // WARNING: fix this to address blanks
        startDatetime,
        'Fact'[Data_Hora_Fech]
    ) 
VAR NormalRange = DATEDIFF( endDatetime, startDatetime, MINUTE )
VAR FilteredRange =
    FILTER (
        GENERATESERIES ( startDatetime, endDatetime, TIME ( 0, 1, 0 ) ),
        NOT WEEKDAY ( [Value] ) IN { 1 } // Sunday
            && NOT (  WEEKDAY ( [Value] ) IN { 7 } && HOUR ( [Value] ) >= 0 && HOUR ( [Value] ) < 12 ) // Saturday
            && NOT ( MONTH ( [Value] ) = 12 && DAY ( [Value] ) = 25 ) // Christmas example
    )

RETURN
    NormalRange - (NormalRange - COUNTROWS ( FilteredRange ) )

A friend gave me this code, but it is giving error, can someone help me?

Olá, este não exclui o sábado inteiro e não somente as horas. 

Greg_Deckler
Super User
Super User

See if this helps:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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