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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
AntiquinaRyan
New Member

INQUIRY: Powerquery Decreasing Value

Hello guys,

 

Good morning.

Apologies in advance for asking this basic question. I'm new to power query and googling did not offer much help when I tried to look for answers (probably due to the keywords I'm using).

 

I'm need help the following:

Considering I have a base value of 100 at the start of the month, I want to know how to have it implemented via powerquery like in the table below:

AntiquinaRyan_0-1724856866572.png

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

I think it can be debated what came first, the attendance or the attrition.

 

Feel free to modify the code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY7BCcAwDMR28TsQn+u07iwh+69RCi0BPSWOQ3NadfXwSGtmq70cP+sTBwbJwcDgBF/g4sGNgZyCkQoKViopmCl2iqGqLdYD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Attrition = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Attrition", Int64.Type}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Attendance", (k)=> 100 - (List.Sum(Table.SelectRows(#"Changed Type", each [Date]<=k[Date])[Attrition])??0),Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Attrition %", each [Attrition]/([Attendance]+[Attrition]),type number)
in
    #"Added Custom1"

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

I think it can be debated what came first, the attendance or the attrition.

 

Feel free to modify the code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY7BCcAwDMR28TsQn+u07iwh+69RCi0BPSWOQ3NadfXwSGtmq70cP+sTBwbJwcDgBF/g4sGNgZyCkQoKViopmCl2iqGqLdYD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Attrition = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Attrition", Int64.Type}, {"Date", type date}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Attendance", (k)=> 100 - (List.Sum(Table.SelectRows(#"Changed Type", each [Date]<=k[Date])[Attrition])??0),Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Attrition %", each [Attrition]/([Attendance]+[Attrition]),type number)
in
    #"Added Custom1"

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.

Hello @lbendlin ,

 

Thank you very much for the response. I'll surely try this one out and the code structure makes sense by initially looking at it. To answer your question, attendance comes first before the attrition.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors