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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
cmilligan262
Helper II
Helper II

Prior month Value Calculated Column

I need to get movement in our roster and need to pull in the prior months cost center name in a calculcated column

 

This is what my data looks like

 

Date                           EMPID                        Cost Center Name

2/29/2020                  001                             Executive

2/29/2020                  002                             Apps

1/31/2020                  001                             Apps

1/31/2020                  002                             Apps

 

Ideally the prior cost center column would show Apps for Emp 001 for 2/29/2020

 

I've tried Calculate(Values(Cost Center Name),Filter(Table,EMPID=Earlier(EMPID)),DATEADD(Date Table(Date,-1,Month))

 

This returns that there is a circular dependency. 

 

Thank you in advance for the help.

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

Perhaps:

 

Column =
  VAR __PreviousDate = MAXX(FILTER('Table',[Date]<EARLIER([Date])&&[EMPID]=EARLIER([EMPID])),[Date])
RETURN
  MAXX(FILTER('Table',[EMPID]=EARLIER([EMPID]) && [Date]=__PreviousDate),[Cost Center Name])

 

  



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
v-easonf-msft
Community Support
Community Support

Hi , @cmilligan262 

Here is a demo.

Pbix attached

 

Try to change your  measure as below:

The prior cost center column =
VAR d = [Date]
RETURN
    CALCULATE (
        MAX ( 'Table'[Cost Center Name] ),
        FILTER (
            'Table',
            'Table'[EMPID] = EARLIER ( 'Table'[EMPID] )
                && 'Table'[Date]
                    >= DATE ( YEAR ( d ), MONTH ( d ) - 1, 1 )
                && 'Table'[Date]
                    <= DATE ( YEAR ( d ), MONTH ( d ), 1 ) - 1
        )
    )

 

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

Greg_Deckler
Community Champion
Community Champion

Perhaps:

 

Column =
  VAR __PreviousDate = MAXX(FILTER('Table',[Date]<EARLIER([Date])&&[EMPID]=EARLIER([EMPID])),[Date])
RETURN
  MAXX(FILTER('Table',[EMPID]=EARLIER([EMPID]) && [Date]=__PreviousDate),[Cost Center Name])

 

  



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you @Greg_Deckler that worked.

 

Do you have any explanation on why that would work and why I was getting a circular dependecy error on the formula I tried

I believe the short answer is that you were using CACULATE in a column formula along with DISTINCT or VALUES and that tends to be bad. @edhans probably has a much deeper and more insightful explanation as I have seen a really great explanation in a separate thread. @edhans would highly recommend making that a blog article.



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
camargos88
Community Champion
Community Champion

Hi @cmilligan262 ,

 

Try this code to create a calculated column:

 

Pior_Cost_Center =
VAR _date = 'Table (2)'[Date]
VAR _maxDate = CALCULATE(MAX('Table (2)'[Date]); FILTER(ALLEXCEPT('Table (2)';'Table (2)'[EMPID]); 'Table (2)'[Date] < _date))
RETURN CALCULATE(DISTINCT('Table (2)'[Cost Center Name]); FILTER(ALLEXCEPT('Table (2)';'Table (2)'[EMPID]); 'Table (2)'[Date] = _maxDate))
 
Ricardo
 


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.