Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi,
How to calculate the last 3 preceding month values and then calculate the average of the first 2 maximum values within those 3 preceding values.
Here my expected output.
Excepted output column comes from Actual Amount.
Thanks,
Ajith
Solved! Go to Solution.
Hi @Ajith_Kumar ,
I created a sample pbix file(see the attachment), please find the details in it.
1. Add index column in Power Query Editor
= Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)
2. Create two measures as below
Last 3 Preceeding value =
VAR _selindex =
SELECTEDVALUE ( 'Table'[Index] )
VAR _minindex =
CALCULATE ( MIN ( 'Table'[Index] ), ALLSELECTED ( 'Table' ) )
RETURN
IF (
_selindex = _minindex,
BLANK (),
CALCULATE (
SUM ( 'Table'[Actual Amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Index] >= _selindex - 3
&& 'Table'[Index] < _selindex
)
)
)
Average of the first 2 maximum values =
VAR _selindex =
SELECTEDVALUE ( 'Table'[Index] )
VAR _tab =
SUMMARIZE (
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Index] >= _selindex - 3
&& 'Table'[Index] < _selindex
),
'Table'[Index],
"@ActualAmt", SUM ( 'Table'[Actual Amount] )
)
VAR _tab2 =
ADDCOLUMNS ( _tab, "@Rank", RANKX ( _tab, [@ActualAmt] ) )
VAR _maxvalue1 =
SUMX ( FILTER ( _tab2, [@Rank] = 1 ), [@ActualAmt] )
VAR _maxvalue2 =
SUMX ( FILTER ( _tab2, [@Rank] = 2 ), [@ActualAmt] )
RETURN
( _maxvalue1 + _maxvalue2 ) / 2
Best Regards
Hi @Ajith_Kumar ,
I created a sample pbix file(see the attachment), please find the details in it.
1. Add index column in Power Query Editor
= Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type)
2. Create two measures as below
Last 3 Preceeding value =
VAR _selindex =
SELECTEDVALUE ( 'Table'[Index] )
VAR _minindex =
CALCULATE ( MIN ( 'Table'[Index] ), ALLSELECTED ( 'Table' ) )
RETURN
IF (
_selindex = _minindex,
BLANK (),
CALCULATE (
SUM ( 'Table'[Actual Amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Index] >= _selindex - 3
&& 'Table'[Index] < _selindex
)
)
)
Average of the first 2 maximum values =
VAR _selindex =
SELECTEDVALUE ( 'Table'[Index] )
VAR _tab =
SUMMARIZE (
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[Index] >= _selindex - 3
&& 'Table'[Index] < _selindex
),
'Table'[Index],
"@ActualAmt", SUM ( 'Table'[Actual Amount] )
)
VAR _tab2 =
ADDCOLUMNS ( _tab, "@Rank", RANKX ( _tab, [@ActualAmt] ) )
VAR _maxvalue1 =
SUMX ( FILTER ( _tab2, [@Rank] = 1 ), [@ActualAmt] )
VAR _maxvalue2 =
SUMX ( FILTER ( _tab2, [@Rank] = 2 ), [@ActualAmt] )
RETURN
( _maxvalue1 + _maxvalue2 ) / 2
Best Regards
User | Count |
---|---|
84 | |
80 | |
70 | |
47 | |
43 |
User | Count |
---|---|
108 | |
54 | |
50 | |
40 | |
40 |