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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Average and Sum in one DAX Measures based on row context

Hi All,
I am trying to achieve the values in the expected result column where I want to have an average of Values column where metric is headcount but sum of Values where metric on the row is Sales and Profit?

Please help, example is given below.

Two questions;
1) How can it be achieved it in clculated column?
2) How can it be achieved through DAX meaure using VAR ?

 

Zubairkh_0-1639917402424.png

 

 

2 ACCEPTED SOLUTIONS
smpa01
Super User
Super User

@Anonymous 

Column =
IF (
    'Table'[Metric] = "Head Count",
    CALCULATE ( AVERAGE ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) ),
    CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) )
)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

Anonymous
Not applicable

Hi @Anonymous ,

I created a sample pbix file(see attachment), please check whether that is what you want. You can create a calculated column or measure as below to get the values:

1. Create a calculated column just as suggested by @smpa01 

Column = 
IF (
    'Table'[Metric] = "Head count",
    CALCULATE (
        AVERAGE ( 'Table'[Values] ),
        ALLEXCEPT ( 'Table', 'Table'[Metric] )
    ),
    CALCULATE ( SUM ( 'Table'[Values] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) )
)

2. Create a measure as below

Measure = 
VAR _selmetric =
    SELECTEDVALUE ( 'Table'[Metric] )
VAR _average =
    AVERAGEX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Metric] = _selmetric ),
        [Values]
    )
VAR _sum =
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Metric] = _selmetric ),
        [Values]
    )
RETURN
    IF ( _selmetric = "Head count", _average, _sum )

yingyinr_0-1640141020835.png

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

I created a sample pbix file(see attachment), please check whether that is what you want. You can create a calculated column or measure as below to get the values:

1. Create a calculated column just as suggested by @smpa01 

Column = 
IF (
    'Table'[Metric] = "Head count",
    CALCULATE (
        AVERAGE ( 'Table'[Values] ),
        ALLEXCEPT ( 'Table', 'Table'[Metric] )
    ),
    CALCULATE ( SUM ( 'Table'[Values] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) )
)

2. Create a measure as below

Measure = 
VAR _selmetric =
    SELECTEDVALUE ( 'Table'[Metric] )
VAR _average =
    AVERAGEX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Metric] = _selmetric ),
        [Values]
    )
VAR _sum =
    SUMX (
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Metric] = _selmetric ),
        [Values]
    )
RETURN
    IF ( _selmetric = "Head count", _average, _sum )

yingyinr_0-1640141020835.png

Best Regards

smpa01
Super User
Super User

@Anonymous 

Column =
IF (
    'Table'[Metric] = "Head Count",
    CALCULATE ( AVERAGE ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) ),
    CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) )
)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 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.