Forum Discussion
Calculate Month over Month Labor Cost
- 3 years ago
Hi mtpirhala ,
According to your description, here's my solution.
Add a custom column.
[Sales Price]-List.Sum(Table.SelectRows(#"Changed Type",(x)=>x[Date]<=[Date])[Total Cost])Get the correct result.
Here's the whole M syntax, you can copy-paste in a blank query to see the details.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtE31DcyMDJU0lEy1DEwMADRYNIUzASSsTrRSqaYqoyQ1BobQJSZ4TLMyBTEBJIgVeZYVEFtAxFmQFWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Sales Price" = _t, #"Labor " = _t, Materials = _t, #"Total Cost" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Sales Price", Int64.Type}, {"Labor ", Int64.Type}, {"Materials", Int64.Type}, {"Total Cost", Int64.Type}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Net", each [Sales Price]-List.Sum(Table.SelectRows(#"Changed Type",(x)=>x[Date]<=[Date])[Total Cost])) in #"Added Custom"I also attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi mtpirhala ,
According to your description, here's my solution.
Add a custom column.
[Sales Price]-List.Sum(Table.SelectRows(#"Changed Type",(x)=>x[Date]<=[Date])[Total Cost])
Get the correct result.
Here's the whole M syntax, you can copy-paste in a blank query to see the details.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtE31DcyMDJU0lEy1DEwMADRYNIUzASSsTrRSqaYqoyQ1BobQJSZ4TLMyBTEBJIgVeZYVEFtAxFmQFWxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"Sales Price" = _t, #"Labor " = _t, Materials = _t, #"Total Cost" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Sales Price", Int64.Type}, {"Labor ", Int64.Type}, {"Materials", Int64.Type}, {"Total Cost", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Net", each [Sales Price]-List.Sum(Table.SelectRows(#"Changed Type",(x)=>x[Date]<=[Date])[Total Cost]))
in
#"Added Custom"
I also attach my sample below for your reference.
Best Regards,
Community Support Team _ kalyj
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.