From c229a298fa70e8ce993a52630fd3082cfdec7688 Mon Sep 17 00:00:00 2001 From: Deniz Saner Date: Mon, 30 Sep 2024 13:43:20 +0200 Subject: [PATCH] make resolution field a single select drop down --- MachineProductivityMetrics.pqm | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/MachineProductivityMetrics.pqm b/MachineProductivityMetrics.pqm index 5b76a4f..872ea5e 100644 --- a/MachineProductivityMetrics.pqm +++ b/MachineProductivityMetrics.pqm @@ -16,23 +16,28 @@ let DateTimeRanges = loadModule("DateTimeRanges.pqm"), PostRequest = loadModule("ApiClient.pqm")[PostRequest], TransformProductivityMetrics = loadModule("Transforms.pqm")[TransformProductivityMetrics], + FunctionSignature = type function ( + machines as table, + start as datetimezone, + end as datetimezone, + resolution as ( + type text meta [ + Documentation.Description = "Select a resolution.", + Documentation.AllowedValues = {"hourly", "daily", "weekly", "monthly"} + ] + ) + ) as table, MachineProductivityMetrics = (machines as table, start as datetimezone, end as datetimezone, resolution as text) as table => let machineUuids = Table.Column(machines, "uuid"), - validResolutions = {"hourly", "daily", "weekly", "monthly"}, - validatedResolution = - if List.Contains(validResolutions, resolution) then - resolution - else - error "Invalid resolution. Please choose 'hourly', 'daily', 'weekly', or 'monthly'.", dateTimeRanges = - if validatedResolution = "hourly" then + if resolution = "hourly" then DateTimeRanges[ToHourlyDateTimeRanges](start, end, resolution) - else if validatedResolution = "daily" then + else if resolution = "daily" then DateTimeRanges[ToDailyDateTimeRanges](start, end) - else if validatedResolution = "weekly" then + else if resolution = "weekly" then DateTimeRanges[ToWeeklyDateTimeRanges](start, end) - else if validatedResolution = "monthly" then + else if resolution = "monthly" then DateTimeRanges[ToMonthlyDateTimeRanges](start, end) else error "Invalid resolution. Please choose 'hourly', 'daily', 'weekly', or 'monthly'.", @@ -52,6 +57,7 @@ let Table.Combine({state, TransformProductivityMetrics(responseDataWithMachine)}) ) in - accumulated + accumulated, + MachineProductivityMetricsCorrectType = Value.ReplaceType(MachineProductivityMetrics, FunctionSignature) in - MachineProductivityMetrics + MachineProductivityMetricsCorrectType