提取具有多个日期的行的最小最大日期
Posted
技术标签:
【中文标题】提取具有多个日期的行的最小最大日期【英文标题】:Extract min max date of a row with multiple dates 【发布时间】:2020-01-25 17:19:09 【问题描述】:如何拆分位于多盘日期行中的最小和最大日期
这是在 Power Query 中
8/31/2018, 8/29/2018, 4/9/2018, 8/29/2018, 8/29/2018
导致不同的列
min max
29/8/2019 4/9/2019
谁能帮我弄清楚?
代码: = Table.TransformColumns(#"Added Custom4", "FechaFinalTarea", each Text.Combine(List.Transform(_, Text.From), ", "), type text)
enter image description here
完整代码: 让 来源 = Etapa_1_Caricam, #"Grouped Rows" = Table.Group(Source, "Num Form", "mynewtable", each _, type table [Num Form=text, DupForm=text, Creado En=date, FechaCreac=date, SLA = 编号,发起者名称 = 文本,业务单位 = 文本,BU 描述 = 文本,提示表单 = 文本,描述 = 文本,文本 tarea = 文本,字段 12 = 编号,任务分配 = 文本,状态 = 编号]) , #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Task_Etapa1", each Table.Column([mynewtable],"Texto tarea")), #"Extracted Values" = Table.TransformColumns(#"Added Custom", "Task_Etapa1", each Text.Combine(List.Transform(, Text.From), ", "), type text), #"Added Custom1" = Table.AddColumn(#"Extracted Values", "Iniciador", each Table.Column([mynewtable],"Initiator Name")), #"Extracted Values1" = Table.TransformColumns(#"Added Custom1", "Iniciador", each Text.Combine(List.Transform(, Text.From), ", "), type text), #"Extracted Text Before Delimiter" = Table.TransformColumns(#"Extracted Values1", "Iniciador", each Text.BeforeDelimiter(, ", "), type text), #"Added Custom2" = Table.AddColumn(#"Extracted Text Before Delimiter", "Custom", each Table.Column([mynewtable],"Descripción del proyecto")), #"Extracted Values2" = Table.TransformColumns(#"Added Custom2", "Custom", each Text.Combine(List.Transform(, Text.From), ", "), type text), #"Inserted Text Before Delimiter" = Table.AddColumn(#"Extracted Values2", "Text Before Delimiter", each Text.BeforeDelimiter([Custom], ","), type text), #"Removed Columns" = Table.RemoveColumns(#"Inserted Text Before Delimiter","Custom"), #"Renamed Columns" = Table.RenameColumns(#"Removed Columns","Text Before Delimiter", "Description del Proyecto"), #"Added Custom3" = Table.AddColumn(#"Renamed Columns", "FechaInicio", each Table.Column([mynewtable],"Creado En")), #"Extracted Values3" = Table.TransformColumns(#"Added Custom3", "FechaInicio", each Text.Combine(List.Transform(, Text.From), ", "), type text), #"Inserted Text Before Delimiter1" = Table.AddColumn(#"Extracted Values3", "Text Before Delimiter", each Text.BeforeDelimiter([FechaInicio], ", "), type text), #"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter1", "Text After Delimiter", each Text.AfterDelimiter([FechaInicio], ", "), type text), #"Removed Columns1" = Table.RemoveColumns(#"Inserted Text After Delimiter","Text After Delimiter", "Text Before Delimiter"), #"Extracted Text Before Delimiter1" = Table.TransformColumns(#"Removed Columns1", "FechaInicio", each Text.BeforeDelimiter(, ", "), type text), #"Added Custom4" = Table.AddColumn(#"Extracted Text Before Delimiter1", "FechaFinalTarea", each Table.Column([mynewtable],"FechaCreac")), #"Extracted Values4" = Table.TransformColumns(#"Added Custom4", "FechaFinalTarea", each Text.Combine(List.Transform(_, Text.From), ", "), type text) 在 #"提取值4"
【问题讨论】:
【参考方案1】:您的输入数据中没有日期 29/8/2019
(或与 2019 年相关的任何日期)。您还以day/month/year
的形式展示了您的“结果”之一。这可能只是几个拼写错误,但会使您的“结果”和问题都不清楚且难以理解。
如果我理解正确,以下方法之一应该可以工作。
如果您的初始表格如下所示(其中所有日期均采用month/day/year
格式并且是单个逗号分隔字符串的一部分):
然后我得到这个输出(注意列 min
和 max
):
使用此代码:
let
initialTable = Table.FromRows("8/31/2018, 8/29/2018, 4/9/2018, 8/29/2018, 8/29/2018"),
split = Table.AddColumn(initialTable, "datesToCheck", each List.Transform(Text.Split([Column1], ","), each Date.FromText(_, "en-US")), type list),
minAndMax = Table.AddColumn(split, "toExpand", each [min = List.Min([datesToCheck]), max = List.Max([datesToCheck])], type record),
expanded = Table.ExpandRecordColumn(minAndMax, "toExpand", "min", "max")
in
expanded
但是,如果您的初始表格如下所示(日期在它们自己的列中开始):
然后我得到这个输出(注意列 min
和 max
):
使用下面的代码:
let
initialTable = Table.FromRows(List.Transform("8/31/2018", "8/29/2018", "4/9/2018", "8/29/2018", "8/29/2018", each Date.FromText(_, "en-US"))),
split = Table.AddColumn(initialTable, "datesToCheck", each Record.FieldValues(_), type list),
minAndMax = Table.AddColumn(split, "toExpand", each [min = List.Min([datesToCheck]), max = List.Max([datesToCheck])], type record),
expanded = Table.ExpandRecordColumn(minAndMax, "toExpand", "min", "max")
in
expanded
根据您的代码,您的表似乎包含一个表列(称为mynewtable
),其中有一个名为FechaCreac
的列,它本身包含日期。我无法对此进行测试,但我建议您在代码中替换这些行:
#"Added Custom4" = Table.AddColumn(#"Extracted Text Before Delimiter1", "FechaFinalTarea", each Table.Column([mynewtable],"FechaCreac")),
#"Extracted Values4" = Table.TransformColumns(#"Added Custom4", "FechaFinalTarea", each Text.Combine(List.Transform(_, Text.From), ", "), type text)
in
#"Extracted Values4"
与:
#"Added Custom4" = Table.AddColumn(#"Extracted Text Before Delimiter1", "FechaFinalTarea", each let dates = Table.Column([mynewtable],"FechaCreac") in [min = List.Min(dates), max = List.Max(dates)]),
expanded = Table.ExpandRecordColumn(#"Added Custom4", "FechaFinalTarea", "min", "max")
in
expanded
然后应该会显示min
和max
列。
【讨论】:
嗨,谢谢您的回答,我已经尝试过,使用您发送的代码并且它运行良好,但是当我在我的初始表中执行它时它不起作用。这是我的代码 @BenCruz,如果您在问题中包含您的代码,我会尝试看看它为什么不起作用。 @BenCruz,看到我回答的结尾,看看我认为你需要做哪些替换。以上是关于提取具有多个日期的行的最小最大日期的主要内容,如果未能解决你的问题,请参考以下文章
删除/隐藏 UIDatePicker 最小/最大日期范围之外的行?