Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
I tried to do the same calculation that my friend @DataNinja777 helped with in this topic , but it didn't work.
How to do this calculation in Power BI?
Mes | Valor1 | Valor2 | Medida |
1 | 277,25 | 476,26 | 0,00 |
2 | 892,78 | 997,81 | 0,00 |
3 | 322,32 | 313,25 | 9,07 |
4 | 557,25 | 734,94 | 0,00 |
5 | 782,88 | 992,08 | 0,00 |
6 | 476,11 | 942,30 | 0,00 |
7 | 1.034,96 | 921,74 | 113,22 |
8 | 1.641,06 | 859,57 | 894,72 |
9 | 544,83 | 1.142,17 | 297,38 |
10 | 1.064,50 | 825,65 | 536,23 |
11 | 710,08 | 626,05 | 620,26 |
12 | 849,20 | 675,70 | 793,77 |
Solved! Go to Solution.
It is impossible to do variable aggregations in Power BI. You can only do these in Power Query, with List.Accumulate.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TZDLEQMxCEN78VmT4WcDteyk/zYCOIe9CfMsBM+zeGGJO2SXMD+QU4JAtL54llQRKfAokekIfre1ChWBNqes1yZBPm2rYu+/uash7f17XkMQ11xA8W6ffyLukWk1hd5tr4I/1K5NpjC87bljyCAxyDEGNRI7sX02MvhFsiOaIXRYrjHciNSuGoMw3UnHsFuGbJzOvrXOpZfpjM50VzhyQHsE9UGHmFNaQtrj+Ia38FR4Xev7Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Mes = _t, Valor1 = _t, Valor2 = _t, Medida = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Mes", Int64.Type},{"Valor1", Currency.Type}, {"Valor2", Currency.Type}, {"Medida", Currency.Type}},"es"),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Medida2", each List.Accumulate({1..[Mes]},List.Max({0,#"Changed Type"{0}[Valor1]-#"Changed Type"{0}[Valor2]}),(state,current)=> List.Max({0,#"Changed Type"{current-1}[Valor1]-#"Changed Type"{current-1}[Valor2]+state})), Currency.Type)
in
#"Added Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
It is impossible to do variable aggregations in Power BI. You can only do these in Power Query, with List.Accumulate.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TZDLEQMxCEN78VmT4WcDteyk/zYCOIe9CfMsBM+zeGGJO2SXMD+QU4JAtL54llQRKfAokekIfre1ChWBNqes1yZBPm2rYu+/uash7f17XkMQ11xA8W6ffyLukWk1hd5tr4I/1K5NpjC87bljyCAxyDEGNRI7sX02MvhFsiOaIXRYrjHciNSuGoMw3UnHsFuGbJzOvrXOpZfpjM50VzhyQHsE9UGHmFNaQtrj+Ia38FR4Xev7Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Mes = _t, Valor1 = _t, Valor2 = _t, Medida = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Mes", Int64.Type},{"Valor1", Currency.Type}, {"Valor2", Currency.Type}, {"Medida", Currency.Type}},"es"),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Medida2", each List.Accumulate({1..[Mes]},List.Max({0,#"Changed Type"{0}[Valor1]-#"Changed Type"{0}[Valor2]}),(state,current)=> List.Max({0,#"Changed Type"{current-1}[Valor1]-#"Changed Type"{current-1}[Valor2]+state})), Currency.Type)
in
#"Added Custom"
How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.
User | Count |
---|---|
102 | |
91 | |
87 | |
79 | |
71 |
User | Count |
---|---|
113 | |
105 | |
101 | |
75 | |
64 |