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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jaybears130
Frequent Visitor

Calculated Column Showing Previous Month's Value

I have a table with price indexes for a list of SeriesID's dated for the end of every month.  I want to add a column that will show me the previous month's index for each particular SeriesID in my table.  Can anyone help?

jaybears130_0-1627013692254.png

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @jaybears130 ,

You can create a calculated column as below:

Previous Month's Value = 
VAR _curmonthnum = 'Table'[Month Number]
VAR _curyear = 'Table'[Year]
VAR _year =
    IF ( _curmonthnum = 1, _curyear - 1, _curyear )
VAR _monthnum =
    IF ( _curmonthnum = 1, 12, _curmonthnum - 1 )
RETURN
    CALCULATE (
        MAX ( 'Table'[value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[seriesID] = EARLIER ( 'Table'[seriesID] )
                && 'Table'[Year] = _year
                && 'Table'[Month Number] = _monthnum
        )
    )

yingyinr_0-1627291235110.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @jaybears130 ,

You can create a calculated column as below:

Previous Month's Value = 
VAR _curmonthnum = 'Table'[Month Number]
VAR _curyear = 'Table'[Year]
VAR _year =
    IF ( _curmonthnum = 1, _curyear - 1, _curyear )
VAR _monthnum =
    IF ( _curmonthnum = 1, 12, _curmonthnum - 1 )
RETURN
    CALCULATE (
        MAX ( 'Table'[value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[seriesID] = EARLIER ( 'Table'[seriesID] )
                && 'Table'[Year] = _year
                && 'Table'[Month Number] = _monthnum
        )
    )

yingyinr_0-1627291235110.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

@jaybears130 , I am not seeing index. I am assuming you need value

 

New column

 


Last Month Value =
var _1 = eomonth([Date] ,-1)

var _3 = [SeriesID]
return
sumx(filter(Table, eomonth([Date] ,0) = _1 && [SeriesID] =_3), [Value])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.