Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin 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.
Hi Everyone,
This is probably very simple but has been breaking my spirit trying to resolve.
I have a dataset that looks like this:
And in the end highlighted column, I have calculated the using the following DAX:
Home Team Over 2.5 Count =
CALCULATE (
SUM ( Fixtures[Over 2.5] ),
FILTER (
Fixtures,
ISNUMBER ( Fixtures[Total Goals] )
&& Fixtures[Date] < EARLIER ( Fixtures[Date])
&& Fixtures[Home Team] = EARLIER(Fixtures[Home Team]))
)
As you can see, this calculation is totalling all the rows in the table where the date is before the current row date and the home team is equal to the current row home team. I would like to take this calculation further by having it sum only the 5 most recent rows where the home team is equal to the row home team and the dates are before the current row date.
I've tried to use TOPN function in what makes logical sense to me, but without success. Does anyone have any idea on how this could be done?
TIA
Solved! Go to Solution.
@Bvalen , Create rank column and trying using
new columns
rank = rankx(filter(Fixtures,Fixtures[Home Team] ,= EARLIER(Fixtures[Home Team]), Fixtures[Date],,asc,dense)
Home Team Over 2.5 Count =
CALCULATE (
SUM ( Fixtures[Over 2.5] ),
FILTER (
Fixtures,
ISNUMBER ( Fixtures[Total Goals] )
&& Fixtures[rank] < EARLIER ( Fixtures[rank]) && && Fixtures[rank] >= EARLIER ( Fixtures[rank]) -5
&& Fixtures[Home Team] = EARLIER(Fixtures[Home Team]))
)
Hi @Bvalen
The easiest way would be to add an index in PQ that gives you the order per date and home team. With that, you can just do the filtering based on
Fixtures[Index] >= (EARLIER ( Fixtures[Index]) - 5) && Fixtures[Index] < EARLIER ( Fixtures[Index])
It can also be done without the index, looking for the last 5 dates before the filtering, but it gets unnecessarily complicated.
Add some sample data and we can get more specific.
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
@Bvalen , Create rank column and trying using
new columns
rank = rankx(filter(Fixtures,Fixtures[Home Team] ,= EARLIER(Fixtures[Home Team]), Fixtures[Date],,asc,dense)
Home Team Over 2.5 Count =
CALCULATE (
SUM ( Fixtures[Over 2.5] ),
FILTER (
Fixtures,
ISNUMBER ( Fixtures[Total Goals] )
&& Fixtures[rank] < EARLIER ( Fixtures[rank]) && && Fixtures[rank] >= EARLIER ( Fixtures[rank]) -5
&& Fixtures[Home Team] = EARLIER(Fixtures[Home Team]))
)
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 79 | |
| 38 | |
| 31 | |
| 27 | |
| 27 |