Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
rmalhan12
Frequent Visitor

Rolling 12 Months per Unique Reference - Power Query

I am aiming to build a custom column which calculates the total rolling 12 months based on a unique reference. I want it to return the values by each row in the 12 month column. I have tried many different ways to no success. Would like some assistance/guidance. Thanks in advance. 

 

Report Date      Ref          Income      Rolling12MonthIncome

30/12/20           1025       £20            return the Income column total where the Ref column is "1025" based on 12 month report date

30/11/20           1029       £30            return the Income column total where the Ref column is "1029" based on 12 month report date

30/10/20           1025       £50            return the Income column total where the Ref column is "1025" based on 12 month report date

1 ACCEPTED SOLUTION
MahyarTF
Memorable Member
Memorable Member

Hi,

Create the below measure in your table :

YTD Income =
Var _LastDate = LASTDATE(Sheet155[Report Date])
Var _TotalLast = CALCULATE( sum(Sheet155[Income]),
                            ALLEXCEPT(Sheet155,Sheet155[Ref]),
                            DATESBETWEEN(Sheet155[Report Date], _LastDate - 365, _LastDate)
                         )
return _TotalLast
MahyarTF_0-1662111108583.png

Appreciate your Kudos

Mahyartf

View solution in original post

6 REPLIES 6
rmalhan12
Frequent Visitor

Any other suggestions would be greatly appreciated. 

MahyarTF
Memorable Member
Memorable Member

Hi,

Create the below measure in your table :

YTD Income =
Var _LastDate = LASTDATE(Sheet155[Report Date])
Var _TotalLast = CALCULATE( sum(Sheet155[Income]),
                            ALLEXCEPT(Sheet155,Sheet155[Ref]),
                            DATESBETWEEN(Sheet155[Report Date], _LastDate - 365, _LastDate)
                         )
return _TotalLast
MahyarTF_0-1662111108583.png

Appreciate your Kudos

Mahyartf

Is there a method to build it into the actual data table as it is more dynamic. Above method I believe is on a visualisation as I have further conditional analysis to do after this step. 

Hi,

You could create the column with same code an it is one of the table's coumn

Mahyartf
rmalhan12
Frequent Visitor

rmalhan12_0-1662109578200.png

I get the following error message, the reference begins with letters

 

amitchandak
Super User
Super User

@rmalhan12 , Try a new column

 


A New column =
var _max = eomonth([Report Date], 0)
var _min = eomonth([Report Date], -12) +1
return
sumx(filter(Table, [Ref] =earlier([Ref]) && [Report Date] <= _max && [Report Date] >= _min), [Income])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors