Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi Guys
How do I get previous value from last month into a new column?
Date | Cumulative Sales | Previous Month **bleep** Sales |
01/06/2018 | 10 | 0 |
01/07/2018 | 20 | 10 |
01/08/2018 | 30 | 20 |
Solved! Go to Solution.
@KH11NDR here you go. Use the PARALLELPERIOD function to get the desired result.
@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.
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:
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,.
@KH11NDR here you go. Use the PARALLELPERIOD function to get the desired result.
@Anonymous
I'm still not getting any figures, I've added my date to a master calendar too.
@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.
Previous month = CALCULATE(SUM(Merge1[Cumulative Revenue]),PARALLELPERIOD(Merge1[Date],-1,MONTH))
@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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
94 | |
77 | |
65 | |
53 |
User | Count |
---|---|
147 | |
106 | |
104 | |
87 | |
61 |