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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
amabrenda1986
Resolver I
Resolver I

Case Age between two dates excluding holiday and weekends

Hello
 
I want to:
a. calculate the case age between two dates (created on Date and Completed On date), if the status = Close or Resolved or Cancelled Or
b. Calculate the case age between two dates (created On and Today), if the status = Active
 
in Power BI, with the exclusion of holidays and Weekends.
 
Please note that I have a table which i have created a calendar table where I have specified the workdays and holidays and weekends. See screen shot below.
 
amabrenda1986_1-1692887974970.png

Specifically, can someone please help me with the formula to calculate the Case Age in Power BI?

 
THANK YOU IN ADVANCE
1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @amabrenda1986 ,

Please try below steps:

1. you need create a date table that record the holiday date, i create a holiday Table 2 for test

Table 2:

vbinbinyumsft_0-1693288965503.png

Table:

vbinbinyumsft_1-1693289003174.png

 

2. create a new column for Table with below dax formula

Column =
VAR _status = [StatusCode]
VAR _start = [CreatedOn]
VAR _end = [CompletedOn]
VAR tmp =
    SELECTCOLUMNS ( 'Table 2', "Date", [Date] )
VAR _val =
    SWITCH (
        [StatusCode],
        "Active", NETWORKDAYS ( _start, TODAY (), 1, tmp ),
        "Resolved", NETWORKDAYS ( _start, _end, 1, tmp ),
        "Cancelled", NETWORKDAYS ( _start, _end, 1, tmp )
    )
RETURN
    _val

vbinbinyumsft_2-1693289085880.png

 

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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

7 REPLIES 7
v-binbinyu-msft
Community Support
Community Support

Hi @amabrenda1986 ,

Please try below steps:

1. you need create a date table that record the holiday date, i create a holiday Table 2 for test

Table 2:

vbinbinyumsft_0-1693288965503.png

Table:

vbinbinyumsft_1-1693289003174.png

 

2. create a new column for Table with below dax formula

Column =
VAR _status = [StatusCode]
VAR _start = [CreatedOn]
VAR _end = [CompletedOn]
VAR tmp =
    SELECTCOLUMNS ( 'Table 2', "Date", [Date] )
VAR _val =
    SWITCH (
        [StatusCode],
        "Active", NETWORKDAYS ( _start, TODAY (), 1, tmp ),
        "Resolved", NETWORKDAYS ( _start, _end, 1, tmp ),
        "Cancelled", NETWORKDAYS ( _start, _end, 1, tmp )
    )
RETURN
    _val

vbinbinyumsft_2-1693289085880.png

 

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amabrenda1986
Resolver I
Resolver I

Please can someone tell me what is wrong with this query

Age = IF(Intakes[value.statecode@OData.Community.Display.V1.FormattedValue]="Active",
IF(CALENDAR([Work Hours]>0,
DATEDIFF(Intakes[value.createdon@OData.Community.Display.V1.FormattedValue],TODAY(),DAY))
 
it gives an error message
amabrenda1986
Resolver I
Resolver I

I used this formular but how do i exclude holidays and Weekends please

Age = IF(Intakes[value.statecode@OData.Community.Display.V1.FormattedValue]="Active",
DATEDIFF(Intakes[value.createdon@OData.Community.Display.V1.FormattedValue],TODAY(),DAY),
DATEDIFF(Intakes[value.createdon@OData.Community.Display.V1.FormattedValue],Intakes[value.coc_completedon@OData.Community.Display.V1.FormattedValue],DAY))
amabrenda1986
Resolver I
Resolver I

See sample extract of my fact table

amabrenda1986_0-1692895300216.png

 

exctract from date table 

amabrenda1986_1-1692895391719.png

 

 

Greg_Deckler
Super User
Super User

@amabrenda1986 That just looks like a date table. What does your fact table look like? Normally these days you would use the NETWORKDAYS function.


Follow on LinkedIn
@ 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...

I am expecting a formula that will

  1. calculate the date difference between the created date and today, with the exclusion of holidays and weekends if the status = Active

  2. Calculate the date difference between created date and completed date, with the exclusion of holidays and weekends if the status = Completed or cancelled

my fact table has a created on date and completed on date with the statuses. 

hope this information is sufficient for you to give me an answer please

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.