Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 3 | |
| 3 | |
| 2 |