Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.
ReportDate | Sales |
1/1/2022 | 61 |
1/2/2022 | 86 |
1/3/2022 | 64 |
1/4/2022 | 69 |
1/5/2022 | 62 |
1/6/2022 | 96 |
1/7/2022 | 64 |
1/8/2022 | 60 |
1/9/2022 | 71 |
1/10/2022 | 79 |
1/11/2022 | 69 |
1/12/2022 | 73 |
The requirement is to get the average sales of the biggest two month in the last six months.
Solved! Go to Solution.
Hi,
In case you do not have a calendar table, please try below.
Please check the below picture and the attached pbix file.
Expected result measure: =
VAR _currentmonthend =
EOMONTH ( MAX ( Data[ReportDate] ), 0 )
VAR _sixmonthboforestart =
EOMONTH ( MAX ( Data[ReportDate] ), -6 ) + 1
VAR _sixmonthsperiodtable =
CALCULATETABLE (
Data,
Data[ReportDate] >= _sixmonthboforestart,
Data[ReportDate] <= _currentmonthend
)
VAR _biggesttwovaluesavg =
AVERAGEX ( TOPN ( 2, _sixmonthsperiodtable, Data[Sales], DESC ), Data[Sales] )
RETURN
_biggesttwovaluesavg
It works well. Thank you Jihwan.
Hi,
In case you do not have a calendar table, please try below.
Please check the below picture and the attached pbix file.
Expected result measure: =
VAR _currentmonthend =
EOMONTH ( MAX ( Data[ReportDate] ), 0 )
VAR _sixmonthboforestart =
EOMONTH ( MAX ( Data[ReportDate] ), -6 ) + 1
VAR _sixmonthsperiodtable =
CALCULATETABLE (
Data,
Data[ReportDate] >= _sixmonthboforestart,
Data[ReportDate] <= _currentmonthend
)
VAR _biggesttwovaluesavg =
AVERAGEX ( TOPN ( 2, _sixmonthsperiodtable, Data[Sales], DESC ), Data[Sales] )
RETURN
_biggesttwovaluesavg
User | Count |
---|---|
10 | |
8 | |
5 | |
5 | |
4 |