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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.