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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sabeensp
Helper IV
Helper IV

Last 12 Month Extract

Hello,

 

I'm new to PBI. 

I have a table with many columns including Year and Month. I need to SUMMARIZE table into another table with only last 12 months data. We do not have DATE Dimmension in the model. Also this table does not have current month data, it has upto last month data. IN my current table max month is Oct. I need to just get Year and Month Going back to Nov 

Year   Month
2018  6

2018  6

2018  6

2018  6

2018  6

2018  7

2018  7

and so on

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Perhaps something like:

 

Table 1 = 
VAR __year = MAX('Table'[Year])
VAR __yearPrev = __year - 1
VAR __month = MAXX(FILTER('Table',[Year]=__year),[Month])
VAR __table = FILTER('Table',[Year] = __year || ([Year] = __yearPrev && [Month] > __month))
RETURN
SUMMARIZE(__table,[Year],[Month],"My Column",SUM([Value]))

Also, I feel that this link might come in handy for you:


https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Perhaps something like:

 

Table 1 = 
VAR __year = MAX('Table'[Year])
VAR __yearPrev = __year - 1
VAR __month = MAXX(FILTER('Table',[Year]=__year),[Month])
VAR __table = FILTER('Table',[Year] = __year || ([Year] = __yearPrev && [Month] > __month))
RETURN
SUMMARIZE(__table,[Year],[Month],"My Column",SUM([Value]))

Also, I feel that this link might come in handy for you:


https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks

 

VAR __month = MAXX(FILTER('Table',[Year]=__year),[Month]) -- This row is not letting meselect Month from the table

Make sure to replace 'Table' with the name of your actual table. Does your table have a Month column? I have this working in a model, you want "Table 1" in the attached file. This builds a table based upon the "Calendar" table.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks, I missed typed your MAXX with MAX,

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.