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
michaelshparber
Advocate V
Advocate V

Dynamic average calculation with disconnected time dimension

Hello friends,

I need to calculate an agerage age (in days) of all open customer cases - historically.

Below is the format of my table.

Until a case has a closed date - it is considered open.

I am struggling to calculate the average age with disconnected dimention.

For the first case for example - I need it to be 1 on 02-Jan-18, 2 on 03-Jan-18, 20 on 21-Jan-18, etc.

When the second case is also open - it should lower the average. So on 22-Jan-18 the calculation should be (21+1)/2 = 11 days.

I tried something like: 

AVERAGEX('Case',MAX('Calendar'[Date])-'Case'[CreatedDate]) but no success
Please help
Thanks!
Michael
CaseIdCreatedDateClosedDate
12301/01/201830/05/2018
45621/01/201814/06/2018
78910/02/2018 
95102/03/201814/07/2018
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @michaelshparber ,

 

Try the following measure:

 

Average =
DIVIDE (
    SUMX (
        FILTER (
            'Case';
            'Case'[CreatedDate] <= MAX ( 'Calendar'[Date] )
                && (
                    'Case'[ClosedDate] >= MAX ( 'Calendar'[Date] )
                        || 'Case'[ClosedDate] = BLANK ()
                )
        );
        DATEDIFF ( 'Case'[CreatedDate]; MAX ( 'Calendar'[Date] ); DAY ) + 1
    );
    CALCULATE (
        DISTINCTCOUNT ( 'Case'[CaseId] );
        FILTER (
            'Case';
            'Case'[CreatedDate] <= MAX ( 'Calendar'[Date] )
                && (
                    'Case'[ClosedDate] >= MAX ( 'Calendar'[Date] )
                        || 'Case'[ClosedDate] = BLANK ()
                )
        )
    )
)

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @michaelshparber ,

 

Try the following measure:

 

Average =
DIVIDE (
    SUMX (
        FILTER (
            'Case';
            'Case'[CreatedDate] <= MAX ( 'Calendar'[Date] )
                && (
                    'Case'[ClosedDate] >= MAX ( 'Calendar'[Date] )
                        || 'Case'[ClosedDate] = BLANK ()
                )
        );
        DATEDIFF ( 'Case'[CreatedDate]; MAX ( 'Calendar'[Date] ); DAY ) + 1
    );
    CALCULATE (
        DISTINCTCOUNT ( 'Case'[CaseId] );
        FILTER (
            'Case';
            'Case'[CreatedDate] <= MAX ( 'Calendar'[Date] )
                && (
                    'Case'[ClosedDate] >= MAX ( 'Calendar'[Date] )
                        || 'Case'[ClosedDate] = BLANK ()
                )
        )
    )
)

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Amazing! Thank you very much @MFelix !

It is working!

Later I'll try to make this work directly with AVERAGEX - I think it is also possible...

Thanks a lot for your quick help!

Have a great wekend!

Michael

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.