Forum Discussion

uk-roberto92's avatar
uk-roberto92
Frequent Visitor
1 year ago
Solved

Average by group ignoring Sub-Group

Hi,   I have a table of the form:   Id     Group   Sub-Group    value 1          A           1A                 10 2          A            2C                 50 3          B            1A     ...
  • Ritaf1983's avatar
    1 year ago

    Hi uk-roberto92 
    You can use a dax measure :

    Group average = 
    VAR selectedGroup = SELECTEDVALUE('Table'[Group])
    VAR AVG_ =
    CALCULATE(
    AVERAGEX(
    SUMMARIZE('Table', 'Table'[Group], "Sum_", AVERAGE('Table'[Value])),
    [Sum_]
    ),
    ALLSELECTED('Table'[Sub-Group]),
    KEEPFILTERS('Table'[Group] = selectedGroup)
    )
    RETURN
    AVG_

     

    Important Notes:

    1. Tooltip Dependency for Sorting
      To sort the bars according to the group, you need to add the Group field into the Tooltips section — as shown in the image.
      This ensures the "Group average" line aligns with each bar correctly by maintaining group context.

    2. Granularity Mismatch – Line May Disappear
    Due to the granularity difference between the Sub-Group (X-axis) and Group average (aggregated by Group), the line won’t appear for the first bar unless you structure your visual hierarchically — like in the second image where the hierarchy is visualized.

    3. 

    Visual Misinterpretation – Lines Suggest Trends
    A line chart (or combo chart with a line) is typically interpreted by users as a trend over time.
    Since this visual is not time-based, to avoid misleading your users, I recommend replacing the line with just markers, like in the third image.
    This keeps the message clear — you're showing averages per group, not a time-based trend.

    Alternatively, you can:

    • Show a single visual with the overall average,

     

    • And create a second chart showing the delta from group average.

    The pbix is attached

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