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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Naveen112
Regular Visitor

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

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 @Naveen112 

 

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 @Naveen112 

 

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,

Surya9
Resolver III
Resolver III

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

 

Surya9_0-1715258246263.png

Check this

 

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.

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

Surya9_0-1715261908620.png

 

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

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

Surya9_0-1715262629541.png

 

 

@Naveen112 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/3395....
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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.