Created
July 29, 2023 18:28
-
-
Save bjulius/2b0b25cfaaf12e80ff3213ecec0a437e to your computer and use it in GitHub Desktop.
Excel BI Power Query 99 Challenge - Brian Julius solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], | |
Type = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Amount", Int64.Type}}), | |
AddShortMon = Table.AddColumn(Type, "Month", each Text.Start( Date.MonthName( [Date] ), 3)), | |
Group = Table.Group(AddShortMon, {"Month"}, {{"Min", each List.Min([Amount]), type nullable number}, {"Max", each List.Max([Amount]), type nullable number}, {"All", each _, type table [Date=nullable date, Amount=nullable number, Month=text]}}), | |
Expand = Table.ExpandTableColumn(Group, "All", {"Date", "Amount"}, {"Date", "Amount"}), | |
AddMinDate = Table.AddColumn(Expand, "MinDate", each if [Amount] = [Min] then [Date] else null, type text), | |
AddMaxDate = Table.AddColumn(AddMinDate, "MaxDate", each if [Amount] = [Max] then [Date] else null, type text), | |
Regroup = Table.Group(AddMaxDate, {"Month", "Min", "Max", "Amount"}, {{"MinDate2", each Text.Combine(List.Transform([MinDate], Text.From ), ", "), type nullable text},{"MaxDate2", each Text.Combine(List.Transform([MaxDate], Text.From ), ", "), type nullable text}}), | |
ReReGroup = Table.Group(Regroup, {"Month", "Min", "Max"}, {{"Min Date", each List.Max([MinDate2]), type nullable text}, {"Max Date", each List.Max([MaxDate2]), type nullable text}}), | |
Reorder = Table.ReorderColumns(ReReGroup,{"Month", "Min", "Min Date", "Max", "Max Date"}) | |
in | |
Reorder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment