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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
denxx34
Frequent Visitor

Calculate Running AVG Cumulative over groups

Hello everyone, I hope you can help me... thanks in advance!!

 

The following scenario: We have objects. When these objects break, a service call is recorded. It's about calculating the average downtime.

There are the master data tables: service call & object.
A fact table FactSvcCall that provides the number of down days and the order.
And there is calendar table.

 

Sample Data:

 

Object

Obj_id  Obj_name
SO1002438 Abc Def
SO2076722 Ghi Jk

 

Service call

Svc_idSvc_name
SV0014407A
SV0018844B
SV0020838C
SV0024112sdf
SV0028077gds
SV0000572degf
SV0000762hwsa
SV0000741edgfr
SV0001435hds
SV0001870adsdf
SV0002316hbdfg
SV0002692dfrghh
SV0003552asdggha
SV0003827ghaadgf
SV0003852gdaag
SV070004171 ghaadfgf

 

FactSvcCall

Call_id Obj_idSvc_idDate_call     DaysBetweenFailure i_index
1SO1002438 SV001440716.12.20198401
2SO1002438SV001884427.07.20202242
3SO1002438SV002083823.11.20201193
4SO1002438SV002411211.05.20211694
5SO1002438SV002807724.11.20211975
6SO2076722SV000057213.02.20213451
7SO2076722SV000076222.03.202163
8SO2076722SV000074116.03.2021312
9SO2076722SV000143505.07.20211054
10SO2076722SV000187022.09.2021795
11SO2076722SV000231606.12.2021756
12SO2076722SV000269209.02.2022657
13SO2076722SV000355208.06.20221198
14SO2076722SV000382715.07.2022379
15SO2076722SV000385222.07.2022710
16SO2076722SV070004171  05.09.2022 4511

 

In addition to the average, I also need the MIN and MAX over the course of time... also cumulatively.

 

The aim is to achieve the following overview:

denxx34_1-1668089148750.png

The group is Svc_id and always calculate the sum of DaysBetweenFailure divided by the number starting from 1 date.

The data model:

denxx34_2-1668089276748.png

 

Is there a way to calculate measures (Avg, Min, Max) so that you can then also flexibly filter based on the data model, i.e. get values from dimension tables in the normal way?

 

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

Hi, @denxx34 

Please try formula like below:

cmulatively count =
CALCULATE (
    DISTINCTCOUNT ( FactSvcCall[i_index] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)
cumulatively sum =
CALCULATE (
    SUM ( FactSvcCall[DaysBetweenFailure] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)
Avg = [cumulatively sum]/[cmulatively count] 
Max =
CALCULATE (
    MAX ( FactSvcCall[DaysBetweenFailure] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)
Min =
CALCULATE (
    MIN ( FactSvcCall[DaysBetweenFailure] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)

veasonfmsft_0-1668160287952.png

Best Regards,
Community Support Team _ Eason

View solution in original post

1 REPLY 1
v-easonf-msft
Community Support
Community Support

Hi, @denxx34 

Please try formula like below:

cmulatively count =
CALCULATE (
    DISTINCTCOUNT ( FactSvcCall[i_index] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)
cumulatively sum =
CALCULATE (
    SUM ( FactSvcCall[DaysBetweenFailure] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)
Avg = [cumulatively sum]/[cmulatively count] 
Max =
CALCULATE (
    MAX ( FactSvcCall[DaysBetweenFailure] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)
Min =
CALCULATE (
    MIN ( FactSvcCall[DaysBetweenFailure] ),
    FILTER (
        ALLSELECTED ( FactSvcCall ),
        FactSvcCall[Obj_id] = MAX ( Object[Obj_id] )
            && FactSvcCall[i_index] <= MAX ( FactSvcCall[i_index] )
    )
)

veasonfmsft_0-1668160287952.png

Best Regards,
Community Support Team _ Eason

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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