Forum Discussion
Anonymous
6 years agoNot applicable
Calculate average of values between defined values
Hi all, I am looking to find the average of some values that lie between changover being 'Yes'. Part Cycle Time (minutes) ChangeoverStatus 1 5.9 No 1 5.2 No 1 5.7 No 1 ...
- 6 years ago
Hi Anonymous
Thanks to HotChilli's suggestion, modify it and create a measure as below, please check if it works for your case.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLVswSSfvlKsTowASN0AXNUAUNzPVMgFZlaDBYCKTfTM0SogQiYowsYExAwNNUzQzIWJGsMFoGqgQiYowsYoQqYgI2FGQJylZGeBZr70T1kAhYA64kFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Part = _t, #"Cycle Time (minutes)" = _t, ChangeoverStatus = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Part", Int64.Type}, {"Cycle Time (minutes)", type number}, {"ChangeoverStatus", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "YesinCol", each if [ChangeoverStatus] = "Yes" then 1 else 0), #"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1), #"Added Custom1" = Table.AddColumn(#"Added Index", "Custom", each List.Sum(List.Range(#"Added Index"[YesinCol], 0, [Index]))), #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom", Int64.Type}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Custom", "Custom index"}}) in #"Renamed Columns"Measure = CALCULATE ( AVERAGE ( Query1[Cycle Time (minutes)] ), FILTER ( ALLSELECTED ( Query1 ), Query1[Part] = MAX ( Query1[Part] ) && Query1[ChangeoverStatus] = "No" && Query1[Custom index] = MAX ( Query1[Custom index] ) ) )Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-juanli-msft
6 years agoCommunity Support
Hi Anonymous
Thanks to HotChilli's suggestion, modify it and create a measure as below, please check if it works for your case.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLVswSSfvlKsTowASN0AXNUAUNzPVMgFZlaDBYCKTfTM0SogQiYowsYExAwNNUzQzIWJGsMFoGqgQiYowsYoQqYgI2FGQJylZGeBZr70T1kAhYA64kFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Part = _t, #"Cycle Time (minutes)" = _t, ChangeoverStatus = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Part", Int64.Type}, {"Cycle Time (minutes)", type number}, {"ChangeoverStatus", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "YesinCol", each if [ChangeoverStatus] = "Yes" then 1 else 0),
#"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1),
#"Added Custom1" = Table.AddColumn(#"Added Index", "Custom", each List.Sum(List.Range(#"Added Index"[YesinCol], 0, [Index]))),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom1",{{"Custom", Int64.Type}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Custom", "Custom index"}})
in
#"Renamed Columns"
Measure =
CALCULATE (
AVERAGE ( Query1[Cycle Time (minutes)] ),
FILTER (
ALLSELECTED ( Query1 ),
Query1[Part]
= MAX ( Query1[Part] )
&& Query1[ChangeoverStatus] = "No"
&& Query1[Custom index]
= MAX ( Query1[Custom index] )
)
)
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.