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
LucileP
Regular Visitor

Calculer nombre de jours ouvrés entre deux dates en excluant les jours fériés

Bonjour à tous,

 

Je travaille acutellement sur une base de données sous Power BI composée d'une unique table qui contient plusieurs champs dont notamment plusieurs dates que voici:

  • Date_création
  • Date_en-cours
  • Date_transmis

Je souhaiterais calculer le nombre de jours ouvrés entre Date_création et Date_en-cours et également entre Date_création et Date_transmis le tout en excluant les jours fériés.

Pour ce qui est du nombre de jours ouvrés pas de soucis, j'ai utilisé la méthode Duration.Days dans ma nouvelle colonne personnalisée. Par contre je n'arrive pas à exclure les jours fériés de ma durée retournée.

J'ai cherché une solution sur beaucoup de forums sans succès. La seule que j'ai pu trouver est un fichier .csv du gouvernement recensant l'ensemble des jours fériés entre 1950 et 2050. J'ai donc créé une table jours fériés à partir de ce fichier et ai créé des relations entre les dates de mes deux tables.

Si vous avez des idées n'hésitez pas 😊

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @LucileP 

Create a holiday table and a date table

Capture3.JPG

In date table, add columns

isholiday = RELATED('holiday table'[holiday])

isweekend = IF(WEEKDAY([Date],2) in {6,7},1)

Capture4.JPG

Create columns in "Table",

Capture5.JPG

current-creat =
VAR noworkdays =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            'Table'[creation date] <= 'date'[Date]
                && 'Table'[current date] >= 'date'[Date]
                && ( 'date'[isholiday] = 1
                || 'date'[isweekend] = 1 )
        )
    )
RETURN
    DATEDIFF (
        [creation date],
        [current date],
        DAY
    ) - noworkdays

tran-create =
VAR noworkdays =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            'Table'[creation date] <= 'date'[Date]
                && 'Table'[transform date] >= 'date'[Date]
                && ( 'date'[isholiday] = 1
                || 'date'[isweekend] = 1 )
        )
    )
RETURN
    DATEDIFF (
        [creation date],
        [transform date],
        DAY
    ) - noworkdays

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-juanli-msft
Community Support
Community Support

Hi @LucileP 

Create a holiday table and a date table

Capture3.JPG

In date table, add columns

isholiday = RELATED('holiday table'[holiday])

isweekend = IF(WEEKDAY([Date],2) in {6,7},1)

Capture4.JPG

Create columns in "Table",

Capture5.JPG

current-creat =
VAR noworkdays =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            'Table'[creation date] <= 'date'[Date]
                && 'Table'[current date] >= 'date'[Date]
                && ( 'date'[isholiday] = 1
                || 'date'[isweekend] = 1 )
        )
    )
RETURN
    DATEDIFF (
        [creation date],
        [current date],
        DAY
    ) - noworkdays

tran-create =
VAR noworkdays =
    CALCULATE (
        COUNT ( 'date'[Date] ),
        FILTER (
            'date',
            'Table'[creation date] <= 'date'[Date]
                && 'Table'[transform date] >= 'date'[Date]
                && ( 'date'[isholiday] = 1
                || 'date'[isweekend] = 1 )
        )
    )
RETURN
    DATEDIFF (
        [creation date],
        [transform date],
        DAY
    ) - noworkdays

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Excellent!! I found it helpful to find the difference between two dates considering business days and holidays!

Anonymous
Not applicable

It is just amazing !!!!

Wonderful !!! Thank you so much! 

 

Have a nice day

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.