Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
VilmarSch
Post Partisan
Post Partisan

Do Not Consider If Accumulated Value Is Negative Part2

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?

Captura de tela 2024-04-26 203352.png

 

MesValor1Valor2Medida
1277,25476,260,00
2892,78997,810,00
3322,32313,259,07
4557,25734,940,00
5782,88992,080,00
6476,11942,300,00
71.034,96921,74113,22
81.641,06859,57894,72
9544,831.142,17297,38
101.064,50825,65536,23
11710,08626,05620,26
12849,20675,70793,77
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

It is impossible to do variable aggregations in Power BI. You can only do these in Power Query, with List.Accumulate.

 

lbendlin_0-1714177150647.png

 

 

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.

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

It is impossible to do variable aggregations in Power BI. You can only do these in Power Query, with List.Accumulate.

 

lbendlin_0-1714177150647.png

 

 

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.

@lbendlin thanks for the answers. I believe Microsoft could see this.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.