Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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 ?
Solved! Go to Solution.
@Anonymous
Column =
IF (
'Table'[Metric] = "Head Count",
CALCULATE ( AVERAGE ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) ),
CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) )
)
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 )
Best Regards
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 )
Best Regards
@Anonymous
Column =
IF (
'Table'[Metric] = "Head Count",
CALCULATE ( AVERAGE ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) ),
CALCULATE ( SUM ( 'Table'[Value] ), ALLEXCEPT ( 'Table', 'Table'[Metric] ) )
)
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
9 | |
6 |