Forum Discussion

PowerBI-Newbie's avatar
6 years ago
Solved

Average YTD Calculation Based on User Selection

Hi,

I have the following data:

 

 

I am able to filter out by each year and period and the correct YTD figure displays thanks to help from Power BI Superusers:

 

I now want to change the YTD from being running total to average depending on the user selection.

 

So the following is the intention when the user selects the relevant Period for a particular year:

YearPeriodAverage Planned YTD
19-2019
19-202=(9+16)/2 =12.5
19-203=(9+16+15)/3=13.3
19-204=(9+16+15+14)/4=13.5

 

Please note that the Year and Period slicers are already related to the Period and YTD tables, that's how I've managed to get the right figures for Period and YTD.

 

Any help is greatly appreciated.

  • Icey's avatar
    Icey
    6 years ago

    Hi PowerBI-Newbie ,

     

    How about this:

    Average Planned YTD =
    VAR SelectedPeriod =
        SELECTEDVALUE ( 'Table'[Period] )
    VAR MaxPeriod =
        MAX ( 'Table'[Period] )
    RETURN
        IF (
            SelectedPeriod = BLANK (),
            [Planned (YTD)] / MaxPeriod,
            [Planned (YTD)] / SelectedPeriod
        )
    

     

    Best Regards,

    Icey

     

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

7 Replies

  • Icey's avatar
    Icey
    Community Support

    Hi PowerBI-Newbie ,

     

    Try this:

    Average Planned YTD = CALCULATE ( AVERAGE ( 'Table'[Planned] ), ALLSELECTED ( 'Table'[Period] ) )

     

     

    Best Regards,

    Icey

     

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

    • PowerBI-Newbie's avatar
      PowerBI-Newbie
      Helper IV

      Thanks for your response Icey but I need the user to select only one period at a time from the slicer and when they do then the correct value is displayed. If they select more than one then the correct averages are displayed for each period. Your images show the incorrect YTD averages for other periods when more than one selection is made - in your example, when you select more than one period the average is displaying the same.

       

      If you look at my table in my post, the user selects only Period 1, average YTD 9 is displayed. User selects only Period 2 then 12.5 is displayed. If user selects Period 1 and 2 then 9 is displayed for Period 1 and 12.5 for Period 2.

       

      I hope that makes sense.

      • Icey's avatar
        Icey
        Community Support

        Hi PowerBI-Newbie ,

         

        How about this:

        Average Planned YTD =
        VAR SelectedPeriod =
            SELECTEDVALUE ( 'Table'[Period] )
        VAR MaxPeriod =
            MAX ( 'Table'[Period] )
        RETURN
            IF (
                SelectedPeriod = BLANK (),
                [Planned (YTD)] / MaxPeriod,
                [Planned (YTD)] / SelectedPeriod
            )
        

         

        Best Regards,

        Icey

         

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