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
simber
Helper I
Helper I

Aggregate hourly KPI and cost to daily with dax?

How do I calculate the daily average when I have hourly values of a KPI and cost?

I have this table (which is a subset of a much larger table) below that I want to take the daily average of so I can plot the daily average KPI and the daily average cost in a scatter plot to see the correlation between the performance and the costs.

The KPI is binary in a hourly resolution but is followed up as an average on a larger timeframe.

 

TimeDayKPICOST
2022-08-01 00:002022-08-01120
2022-08-01 01:002022-08-010100
2022-08-01 02:002022-08-01120
2022-08-01 03:002022-08-01040
2022-08-01 04:002022-08-01060
2022-08-01 05:002022-08-01080
2022-08-01 06:002022-08-01070
2022-08-01 07:002022-08-01030
2022-08-01 08:002022-08-01020
2022-08-01 09:002022-08-011-40
2022-08-01 10:002022-08-01060
2022-08-01 11:002022-08-01043
2022-08-01 12:002022-08-01048
2022-08-01 13:002022-08-01060
2022-08-01 14:002022-08-011-30
2022-08-01 15:002022-08-01060
2022-08-01 16:002022-08-01110
2022-08-01 17:002022-08-01090
2022-08-01 18:002022-08-01045
2022-08-01 19:002022-08-01120
2022-08-01 20:002022-08-01048
2022-08-01 21:002022-08-01110
2022-08-01 22:002022-08-01045
2022-08-01 23:002022-08-01060
2022-08-02 00:002022-08-02115
2022-08-02 01:002022-08-02068
2022-08-02 02:002022-08-02112
2022-08-02 03:002022-08-02078
2022-08-02 04:002022-08-02118

 

The resulting "table":

DayKPICOST
2022-08-010,29166740,375
2022-08-020,638,2

 

 

I don't really want a new table, I would prefer if I have 2 measures which give me daily average values as my current report.

 

 

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

Hi @simber ,

I have created a simple sample, please refer to it to see if it helps you.

Create 2 measures.

average cost =
VAR _cost =
    CALCULATE (
        SUM ( 'Table'[COST] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Day] = SELECTEDVALUE ( 'Table'[Day] ) )
    )
VAR _day =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Day] ), ALLSELECTED ( 'Table' ) )
RETURN
    _cost / _day
average kpi =
VAR _kpi =
    CALCULATE (
        SUM ( 'Table'[KPI] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Day] = SELECTEDVALUE ( 'Table'[Day] ) )
    )
VAR _day =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Day] ), ALLSELECTED ( 'Table' ) )
RETURN
    _kpi / _day

vpollymsft_0-1662082073040.png

 

 

If it still does not help, please provide more details with your desired output. 

 

Best Regards

Community Support Team _ Polly

 

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

1 REPLY 1
v-rongtiep-msft
Community Support
Community Support

Hi @simber ,

I have created a simple sample, please refer to it to see if it helps you.

Create 2 measures.

average cost =
VAR _cost =
    CALCULATE (
        SUM ( 'Table'[COST] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Day] = SELECTEDVALUE ( 'Table'[Day] ) )
    )
VAR _day =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Day] ), ALLSELECTED ( 'Table' ) )
RETURN
    _cost / _day
average kpi =
VAR _kpi =
    CALCULATE (
        SUM ( 'Table'[KPI] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Day] = SELECTEDVALUE ( 'Table'[Day] ) )
    )
VAR _day =
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Day] ), ALLSELECTED ( 'Table' ) )
RETURN
    _kpi / _day

vpollymsft_0-1662082073040.png

 

 

If it still does not help, please provide more details with your desired output. 

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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