Forum Discussion

jillw's avatar
jillw
Frequent Visitor
7 years ago

Average Days Open

I am trying to create a  chart similar to the one below that displays the average amount of days that records are open on any given date.

This image is from a table containing different reports and it outputs the correct information. The DAX for the measure used above is as follows:

 

Daily Avg Days Open UCC =
Var _currentDate = SELECTEDVALUE('Date'[Date])
Return (
AVERAGEX(
Filter('UCC', 'UCC'[UCC Date Created] < _currentDate && ('UCC'[UCC Closed Date] >= _currentDate || ISBLANK(UCC[UCC Closed Date]))
),
VAR _closedDate = IF(ISBLANK('UCC'[UCC Closed Date]),_currentDate,'UCC'[UCC Closed Date])
RETURN _closedDate - UCC[UCC Date Created]
)
)
 
The data contained in the table I want to create a similar report for looks like this:
SCAR Record ID#SCAR Date OpenSCAR Closed Date
4743/29/2019 
4733/28/2019 
4723/19/2019 
4713/14/2019 
46412/17/20184/2/2019
46311/20/2018 
46111/12/2018 
45911/7/20183/7/2019
45710/12/20183/7/2019
45610/9/20183/5/2019
45510/5/20184/2/2019
4519/10/2018 
4487/30/201811/28/2018
4467/26/20189/12/2018
4457/26/20189/12/2018

 

The Measure I am using for this table is as follows:

 

Daily Avg Days Open SCAR =
Var _currentDate = SELECTEDVALUE('Date'[Date])
Return (
AVERAGEX(
Filter('SCAR', 'SCAR'[SCAR Date Open] < _currentDate && ('SCAR'[SCAR Closed Date] >= _currentDate || ISBLANK(SCAR[SCAR Closed Date]))
),
VAR _closedDate = IF(ISBLANK(SCAR[SCAR Closed Date]),_currentDate,SCAR[SCAR Closed Date])
RETURN _closedDate - SCAR[SCAR Date Open]
)
)

 

The numbers I am getting are almost twice as big as they should be. I have tried rewriting this code several different ways but I am still coming to the same results. I think I might be missing something else that is causing the data to be skewed. 

3 Replies

  • jillw based on your example data what you are expected to see "avg days" for each day?

  • madbaird's avatar
    madbaird
    Frequent Visitor

    I am having same issue with almost exact same table.  Need average open per month by fiscal year.  Average needs to be by close date and not open date. Meaning if ticket was opened in November and closed in January, the time open should be reported for January.  This is my table exported to Excel and DaysOpen is done in Excel not from BI:


    TicketNbr CreatedOn ClosedOn DateDiff
    TCK-347663 5/3/2021 6/7/2021 35
    TCK-351210 6/1/2021 6/7/2021 6
    TCK-350980 5/28/2021 6/7/2021 10
    TCK-351322 6/1/2021 6/7/2021 6
    TCK-351631 6/3/2021 6/7/2021 4
    TCK-350881 5/27/2021 6/7/2021 11
    TCK-351254 6/1/2021 6/7/2021 6
    TCK-351417 6/2/2021 6/7/2021 5
    TCK-351633 6/3/2021 6/7/2021 4
    TCK-349579 5/18/2021 6/7/2021 20
    TCK-351052 5/28/2021 6/7/2021 10
    TCK-347662 5/3/2021 6/7/2021 35
    TCK-351416 6/2/2021 6/7/2021 5
    TCK-351451 6/2/2021 6/7/2021 5
    TCK-351154 5/31/2021 6/7/2021 7
    TCK-350822 5/27/2021 6/7/2021 11
    TCK-351114 5/29/2021 6/7/2021 9
    TCK-330545 12/2/2020 187
    TCK-338001 2/8/2021 119
    TCK-338245 2/9/2021 118
    TCK-339071 2/17/2021 110
    TCK-339764 2/23/2021 104
    TCK-340275 2/26/2021 101
    TCK-341736 3/11/2021 88
    TCK-342112 3/15/2021 84
    TCK-343390 3/25/2021 74