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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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