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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
maxduff59
Helper II
Helper II

Create a measure to compute the average of sum with some conditions

Hello everybody,

I am really struggling understanding and realizing measures. I have the following dataset : 

 

Capture d’écran 2022-11-21 à 08.32.08.png

 

And I would like to compute the average of the sum of the total distance in a week for each position. 

 

Capture d’écran 2022-11-21 à 08.35.05.png

 

 I tried to create this following mesure but I think that I am missing some informations.

Moyenne Semaine =
AVERAGEX(
SUMMARIZE('Stats_Activités'  
      , 'Stats_Activités'[Year_Week]  
      , 'Stats_Activités'[position_name]  
      , "Distance courue", SUM('Stats_Activités'[total_distance_courue_(m)])  
      ),[Distance courue])

 Thanks in advance for your help and your time 

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

Hi @maxduff59 ,

 

You can try this method:

Table =

SUMMARIZE (

    'Stats_Activités',

    'Stats_Activités'[Year_Week],

    'Stats_Activités'[Position],

    'Stats_Activités'[Joueur],

    "SUM",

        CALCULATE (

            SUM ( 'Stats_Activités'[Distance] ),

            FILTER (

                'Stats_Activités',

                'Stats_Activités'[Position] = EARLIER ( 'Stats_Activités'[Position] )

                    && 'Stats_Activités'[Year_Week] = EARLIER ( 'Stats_Activités'[Year_Week] )

            )

        )

)
Table 2 =

SUMMARIZE (

    'Table',

    'Table'[Position],

    'Table'[Joueur],

    "AUG",

        CALCULATE (

            AVERAGE ( 'Table'[SUM] ),

            FILTER (

                'Table',

                'Table'[Position] = EARLIER ( 'Table'[Position] )

                    && 'Table'[Joueur] = EARLIER ( 'Table'[Joueur] )

            )

        )

)
Table 3 =

SUMMARIZE (

    'Table 2',

    'Table 2'[Position],

    "AUG",

        CALCULATE (

            AVERAGE ( 'Table 2'[AUG] ),

            FILTER ( 'Table 2', 'Table 2'[Position] = EARLIER ( 'Table 2'[Position] ) )

        )

)

The result is:

vyinliwmsft_0-1669024631409.png

 

vyinliwmsft_1-1669024631411.png

 

vyinliwmsft_2-1669024631411.png

 

Hope this helps you.

Here is my PBIX file.

Best Regards,

Community Support Team _Yinliw

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
v-yinliw-msft
Community Support
Community Support

Hi @maxduff59 ,

 

You can try this method:

Table =

SUMMARIZE (

    'Stats_Activités',

    'Stats_Activités'[Year_Week],

    'Stats_Activités'[Position],

    'Stats_Activités'[Joueur],

    "SUM",

        CALCULATE (

            SUM ( 'Stats_Activités'[Distance] ),

            FILTER (

                'Stats_Activités',

                'Stats_Activités'[Position] = EARLIER ( 'Stats_Activités'[Position] )

                    && 'Stats_Activités'[Year_Week] = EARLIER ( 'Stats_Activités'[Year_Week] )

            )

        )

)
Table 2 =

SUMMARIZE (

    'Table',

    'Table'[Position],

    'Table'[Joueur],

    "AUG",

        CALCULATE (

            AVERAGE ( 'Table'[SUM] ),

            FILTER (

                'Table',

                'Table'[Position] = EARLIER ( 'Table'[Position] )

                    && 'Table'[Joueur] = EARLIER ( 'Table'[Joueur] )

            )

        )

)
Table 3 =

SUMMARIZE (

    'Table 2',

    'Table 2'[Position],

    "AUG",

        CALCULATE (

            AVERAGE ( 'Table 2'[AUG] ),

            FILTER ( 'Table 2', 'Table 2'[Position] = EARLIER ( 'Table 2'[Position] ) )

        )

)

The result is:

vyinliwmsft_0-1669024631409.png

 

vyinliwmsft_1-1669024631411.png

 

vyinliwmsft_2-1669024631411.png

 

Hope this helps you.

Here is my PBIX file.

Best Regards,

Community Support Team _Yinliw

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

Thanks a lot. It seems great. 
I just had a little question about the use of EARLIER function in the filter, why do you use that function ?

 

@v-yinliw-msft 

Hi @maxduff59 ,

 

This function is used to be able to get the context of the same position.

 

Best Regards,

Community Support Team _Yinliw

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

amitchandak
Super User
Super User

@maxduff59 , The measure seem correct to me, It will avg other than week position

 

may be you need

Moyenne Semaine =
AVERAGEX(
SUMMARIZE('Stats_Activités'
, 'Stats_Activités'[Year_Week]
, "Distance courue", SUM('Stats_Activités'[total_distance_courue_(m)])
),[Distance courue])

 

or Switch that is based on isfiltered or isinscope

 

IsInScope - Switch Rank at different levels: https://youtu.be/kh0gezKICEM

 

HasOneValue , Isfiltered: https://www.youtube.com/watch?v=hXg3kRFSGjA&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=38

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.