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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mkoontz
Frequent Visitor

Get value from previous record based on Period

I have a table that is by Contract, Period (YYYYMM). I have a measure that is grabbing the previous record based on the Period column. This works great when the previous record is in the same year, but when I go from 202101 to 202012, my measure will not work. I am looking for some guidance on the best approach to grab previous record when it switches years based on my Period column.

 

Previous Value =
    CALCULATE( [measure for column ($)],
        FILTER( ALL( dimDate ),
        dimDate[Period] = SELECTEDVALUE( dimDate[Period] ) - 1
    )
)
ex. 202101 - 1 ( will not get me the 202012 I am looking for). 
 
Any help would be greatly appreciated. Thanks in advance. I will continue looking on my end.
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@mkoontz , Create a rank on YYYYMM in you date table.

a new column

Period Rank = RANKX(all('Date'),'Period'[year period],,ASC,Dense)

 

try measures like these examples 


This Period = CALCULATE( [measure for column ($)], FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])))
Last Period = CALCULATE( [measure for column ($)], FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])-1))

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@mkoontz , Create a rank on YYYYMM in you date table.

a new column

Period Rank = RANKX(all('Date'),'Period'[year period],,ASC,Dense)

 

try measures like these examples 


This Period = CALCULATE( [measure for column ($)], FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])))
Last Period = CALCULATE( [measure for column ($)], FILTER(ALL('Period'),'Period'[Period Rank]=max('Period'[Period Rank])-1))

 

@amitchandak Thank you for the quick reply. Greatly appreciated. Your solution worked great for me.

mkoontz_0-1611766628326.png

Thank you again.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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