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
Anonymous
Not applicable

How to create a column for Previous Value

Hi All, 

 

Expected Output:

Workitem IDState Previous_State
1001backlog 
1001InprogressBacklog
1001DoneInprogress
2001backlog 
2001InprogressBacklog
2001DoneInprogress

 

I am trying to create Previous_State column  based on State .
Written the below DAX but its giving me Done, Backlog instead of  backlog and  Inprogress. 

 

Previous_State=
CALCULATE (
     MAX('table'[State]) ,
        ALLEXCEPT ( 'table', 'table'[Work Item Id] ),
        'table'[State] < EARLIER('table'[State])
     
)
Workitem IDState Previous_State
1001backlog 
1001InprogressDone
1001DoneBacklog
2001backlog 
2001InprogressDone
2001DoneBacklog


Please help,

Thanks,

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Sure, Under transform data >click add column >index column from 1

Surya9_0-1715262629541.png

 

 

View solution in original post

DataNinja777
Super User
Super User

Hi @Anonymous 

 

There are multiple ways to produce you required output, and one of them is as follows:

Create index dimension table which also has previous row side by side.  

DataNinja777_0-1715263406043.png

Create a relationship between your index dimension table and your fact table.  

DataNinja777_1-1715263448181.png

Create a calculated column which produces your required output like below:

DataNinja777_2-1715263478238.png

I attach an example pbix file.  

Best regards,

View solution in original post

8 REPLIES 8
DataNinja777
Super User
Super User

Hi @Anonymous 

 

There are multiple ways to produce you required output, and one of them is as follows:

Create index dimension table which also has previous row side by side.  

DataNinja777_0-1715263406043.png

Create a relationship between your index dimension table and your fact table.  

DataNinja777_1-1715263448181.png

Create a calculated column which produces your required output like below:

DataNinja777_2-1715263478238.png

I attach an example pbix file.  

Best regards,

Anonymous
Not applicable

Use visual level calculation in home tab > new calculation 
and use previous in measure 

 

Anonymous
Not applicable

Surya9_0-1715258246263.png

Check this

 

Anonymous
Not applicable

Hi, Thanks for the reply but I dont think we can use previous on a dimension like previous(state) .

 

Please can some one help me with the exact result which i am expecting as this is an important work which has dependencies.

Anonymous
Not applicable

Create on index column in a table and create measure as shown in below  image

Surya9_0-1715261908620.png

 

Anonymous
Not applicable

HI @Anonymous , Can you please share me the logic for INDEX please. I can replicate and check thank you

Anonymous
Not applicable

Sure, Under transform data >click add column >index column from 1

Surya9_0-1715262629541.png

 

 

@Anonymous Do you have anything that defines "before"? Can you add an Index? If so you can get previous value using a variation of MTBF. See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
 ( __Current - __Previous ) * 1.



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...

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.