Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. 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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
78 | |
76 | |
59 | |
35 | |
33 |
User | Count |
---|---|
100 | |
62 | |
56 | |
47 | |
41 |