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.
Hello guys!
I need your help about a reverse cumulative formula. I get data from file with the cumulative of value and I would like to decompose this value with day-by-day value. How can I do it?
Source data is like this
Date | Cumulative |
01/01/2021 | 0 |
02/01/2021 | 10 |
03/01/2021 | 15 |
04/01/2021 | 23 |
05/01/2021 | 34 |
06/01/2021 | 56 |
07/01/2021 | 78 |
08/01/2021 | 85 |
And I would like to automatically calculate the single day value in the same month, the result should this
Date | Cumulative | Result |
01/01/2021 | 0 | 0 |
02/01/2021 | 10 | 10 |
03/01/2021 | 15 | 5 |
04/01/2021 | 23 | 8 |
05/01/2021 | 34 | 11 |
06/01/2021 | 56 | 22 |
07/01/2021 | 78 | 22 |
08/01/2021 | 85 | 7 |
Could someone help me?
Thank you so much!
Solved! Go to Solution.
Hello @danilomorganti
you can try this approach but it doesn't look on the date but really on the prior cell value. It basically adds a new column with the cumulative-column but shifted down by one row. After that a new column is added where your needed calculation takes place
Here a code example
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc27DQAhDATRXhwjnT8Y3Aui/zbO0hKsNNFL5hxR+zpXNxmickeTE9mzYEvYJPOAJVlM2CLLBdtku2BFVv24Pw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Cumulative = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Cumulative", Int64.Type}}),
GetNewColumnWithPreviousValue = Table.FromColumns
(
Table.ToColumns(#"Changed Type")&{{0}&List.RemoveLastN(#"Changed Type"[Cumulative])},
Table.ColumnNames(#"Changed Type")&{"CumulativeShifted"}
),
#"Added Custom" = Table.AddColumn(GetNewColumnWithPreviousValue, "Result", each [Cumulative]-[CumulativeShifted]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"CumulativeShifted"})
in
#"Removed Columns"
Result
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Hi, @danilomorganti
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a custom column as below.
let
tab=Table.SelectRows(#"Changed Type",(x)=>Date.Month(x[Date])=Date.Month([Date]) and x[Date]<[Date]),
m=try [Cumulative]-Table.Max(tab,"Date")[Cumulative] otherwise [Cumulative]-0
in
m
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @danilomorganti
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a custom column as below.
let
tab=Table.SelectRows(#"Changed Type",(x)=>Date.Month(x[Date])=Date.Month([Date]) and x[Date]<[Date]),
m=try [Cumulative]-Table.Max(tab,"Date")[Cumulative] otherwise [Cumulative]-0
in
m
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello @danilomorganti
you can try this approach but it doesn't look on the date but really on the prior cell value. It basically adds a new column with the cumulative-column but shifted down by one row. After that a new column is added where your needed calculation takes place
Here a code example
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tc27DQAhDATRXhwjnT8Y3Aui/zbO0hKsNNFL5hxR+zpXNxmickeTE9mzYEvYJPOAJVlM2CLLBdtku2BFVv24Pw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Cumulative = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Cumulative", Int64.Type}}),
GetNewColumnWithPreviousValue = Table.FromColumns
(
Table.ToColumns(#"Changed Type")&{{0}&List.RemoveLastN(#"Changed Type"[Cumulative])},
Table.ColumnNames(#"Changed Type")&{"CumulativeShifted"}
),
#"Added Custom" = Table.AddColumn(GetNewColumnWithPreviousValue, "Result", each [Cumulative]-[CumulativeShifted]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"CumulativeShifted"})
in
#"Removed Columns"
Result
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
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.