Search code examples
powerbidaxaverage

Power BI Visual showing Time Series Average Excluding Sliced Value and the Value Separately


I would like to create a visual that shows the average value for all my series in a fact table, and have a slicer that, when utilized, the data set sliced is REMOVED from the average and shown separately. The point of this is to answer "this series compares to the average of the other series, without including itself, in this way."

I can't decide if this can be done in DAX (which I'm still new to ) or would require a calculated table. I performed the feat in excel using sumifs / countifs, and then graphing that next to what is being excluded. I'm sure it's not hard...

Here's the simple data

Date Person Score
1/1/2023 Bob 140
1/1/2023 Sarah 125
1/1/2023 Sam 140
1/1/2023 Alex 155
2/1/2023 Bob 50
2/1/2023 Sarah 185
2/1/2023 Sam 200
2/1/2023 Alex 215
3/1/2023 Bob 230
3/1/2023 Sarah 245
3/1/2023 Sam 260
3/1/2023 Alex 275
4/1/2023 Bob 290
4/1/2023 Sarah 305
4/1/2023 Sam 320
4/1/2023 Alex 335
5/1/2023 Bob 350
5/1/2023 Sarah 365
5/1/2023 Sam 380
5/1/2023 Alex 395

and here's the result in excel:

enter image description here


Solution

  • Create two measures similar to:

    Avg Not Selected = 
      var selectedPerson =
        CALCULATETABLE(
          DISTINCT('YourTable'[Person]),
          ALLSELECTED('YourTable'[Person])
        )
      return
        CALCULATE(
          AVERAGE('YourTable'[Score]),
          NOT ISFILTERED('YourTable'[Person]) ||
          NOT 'YourTable'[Person] IN selectedPerson
        )
    
    
    Avg Selected = 
      var hasSelection =
        CALCULATE(
          ISFILTERED('YourTable'[Person]),
          ALLSELECTED('YourTable'[Person])
        )
      var result = AVERAGE('YourTable'[Score])
      return SWITCH( TRUE(),
        hasSelection, result,
        NOT ISBLANK(result), 0
      )
    

    enter image description here