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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.