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
Anonymous
Not applicable

Sum of Averages

Hello world!~

 

I've been trying to make a sum of averages for a few days and I think I am out of idea ... so I could use some help.

 

Let's say I have this table: 

 

ScriptDateReferenceTimeExecutionTime
Script15 hours ago13x
Script25 hours ago12x
Script35 hours ago11x
Script14 hours ago13x
Script24 hours ago12x
Script34 hours ago11x
Script13 hours ago13x
Script23 hours ago12x
Script33 hours ago11x
Script12 hours ago13x
Script22 hours ago12x
Script32 hours ago11x
Script11 hour ago13x
Script21 hour ago12x
Script31 hour ago11x
Script1now13x
Script2now12x
Script3now11x
Script1now13x
Script2now12x
Script3now11x

 

What I would like to have is a "stacked column chart & line" with my Script's execution time as stacked column grouped per hours with the average reference time for all 3 scripts as line ; just like that (here is an example, the data above isn't here represented) :Capture.PNG

Here, the line is calculated by making an average of all of my reference times which is not what I am looking for. I want it to average Script1's Reference time, same for script2 and script3 SEPARATED and THEN sum up the 3 of them. So following the example above, for the "now" date, my line should be (((13+ 13) / 2) + ((12 + 12) / 2) + ((11 + 11) / 2)) = 36 seconds.

 

Keep in mind that the number of script and the number of script execution per hours can change at any time

Until here I got this DAX measure but it gives me a "dot" and gives the exact same result Smiley Sad:

 

SumOfAvgRefTime = 
VAR AvgRefTime = AVERAGE(Loops[RefTimeInSec])

RETURN
IF( HASONEVALUE(Loops[RefTimeInSec]),
    AvgRefTime,
        SUMX( VALUES(Loops[RefTimeInSec]), AvgRefTime))

 Do you guys now how I could do it?

 

Thanks!

(Please try to use simple words, I'm not english)

1 ACCEPTED SOLUTION

@Anonymous,

 

See code below.

SUMX (
    VALUES ( Table1[Script] ),
    CALCULATE ( AVERAGE ( Table1[ReferenceTime] ) )
)
Community Support Team _ Sam Zha
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

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous

 

Try this modification

 

=
IF (
    HASONEVALUE ( Loops[RefTimeInSec] ),
    AVERAGE ( Loops[RefTimeInSec] ),
    SUMX (
        VALUES ( Loops[RefTimeInSec] ),
        CALCULATE ( AVERAGE ( Loops[RefTimeInSec] ) )
    )
)

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Hey there,

 

Thanks for answering. The measure you gave me didn't really work :Capture.PNG

It's better at least but for this graph, I know that the line should be a163 seconds-constant line . But I see where you were going with it... I'll keep looking for it ; if someone got another idea?

@Anonymous,

 

See code below.

SUMX (
    VALUES ( Table1[Script] ),
    CALCULATE ( AVERAGE ( Table1[ReferenceTime] ) )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

**bleep** you rule! It worked perfectly! Smiley Very HappyHeart

Thanks mate.Capture.PNG

 

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.