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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
KH11NDR
Helper IV
Helper IV

How do I get previous value from last month into a new column?

Hi Guys

 

How do I get previous value from last month into a new column?

 

 

DateCumulative  SalesPrevious Month **bleep** Sales 
01/06/2018100
01/07/20182010
01/08/20183020
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

@KH11NDR here you go. Use the PARALLELPERIOD function to get the desired result. Challenge - Previous Month Sales.PNG

View solution in original post

Anonymous
Not applicable

@KH11NDR Can you post screenshot of the final table where you are testing the solution, the list of values which go in it. Also are you using a calculated column or measure. I am using a measure.

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @KH11NDR, In order to achive Lag(previous value) you need to follow below steps. 

Create two index column one starts with 0 name it as Index0 and other starts with 1 name it as Index1

Do left Join on same table on condition will be Maintable.Index0 = SelfJoinTable.Index1.

Expand the column and select the "previous value" column which will be ur Lag column.

 

Sample query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkrMKlXSUTI0MlaK1QFxc0FcEzMzMNc7sygxD8g3UoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, Rank = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Rank", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 1, 1),
    #"Merged Queries" = Table.NestedJoin(#"Added Index1",{"Index"},#"Added Index1",{"Index.1"},"Added Index1",JoinKind.LeftOuter),
    #"Expanded Added Index1" = Table.ExpandTableColumn(#"Merged Queries", "Added Index1", {"Rank"}, {"Lag.Rank"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Added Index1",{{"Index", Order.Ascending}}),
    #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index", "Index.1"})
in
    #"Removed Columns"

 

Output screesnshot:

 

temp.JPG 

 

And finally replace null with zero.

 Hope above solution will help in your case.

 

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

Suman152

There ha to be an easier way for sure? Thanks Suman, but Power BI, Must have an easier way,.

Anonymous
Not applicable

@KH11NDR here you go. Use the PARALLELPERIOD function to get the desired result. Challenge - Previous Month Sales.PNG

@Anonymous

 

I'm still not getting any figures, I've added my date to a master calendar too.

Anonymous
Not applicable

@KH11NDR Check the format of the date field? The data set I used is pretty simple and straight forward. Here is a snap of my model. Could you send screenshots of your model, your calculations and final results.

 

 Challenge - Previous Month Sales - 1.PNG

 

 

Previous month = CALCULATE(SUM(Merge1[Cumulative Revenue]),PARALLELPERIOD(Merge1[Date],-1,MONTH))

 

data model.png

Anonymous
Not applicable

@KH11NDR Can you post screenshot of the final table where you are testing the solution, the list of values which go in it. Also are you using a calculated column or measure. I am using a measure.

Changed it from Column to Measure and workd like a treat.

 

Thanks

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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