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.
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.
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 |
---|---|
109 | |
106 | |
87 | |
74 | |
66 |
User | Count |
---|---|
125 | |
114 | |
98 | |
81 | |
73 |