Quarter of year power bi - powerbi

i am trying to get quarter from date ..
i tried this query
let
Source = "",
Custom1 = Source,
Custom2 = Calendar2,
Custom3 = let
Source = List.Dates(#date(1996, 1, 1), 500, #duration(1, 0, 0, 0)),#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Renamed Columns" = Table.RenameColumns(#"Converted to Table",{{"Column1", "Date"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),StartDate = #date(2016, 1, 1),
Today = DateTime.Date(DateTime.LocalNow()),
Length = Duration.Days(Today - StartDate),
Custom1 = #"Changed Type",
#"Inserted Year" = Table.AddColumn(Custom1, "Fin Year", each Date.Year([Date]+#duration(184,0,0,0)), Int64.Type),
#"Inserted Month Name" = Table.AddColumn(#"Inserted Year", "Month Name", each Date.MonthName([Date]), type text),
#"Inserted Day Name" = Table.AddColumn(#"Inserted Month Name", "Day Name", each Date.DayOfWeekName([Date]), type text),
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Quarter of Year","Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type),
#"Inserted Month" = Table.AddColumn(#"Inserted Day Name", "Fin Month", each if Date.Month([Date]) >=7 then Date.Month([Date])-6 else Date.Month([Date])+6 , Int64.Type),
#"Inserted Day of Week" = Table.AddColumn(#"Inserted Month", "Day of Week", each Date.DayOfWeek([Date])+1, Int64.Type),
#"Inserted First Characters" = Table.AddColumn(#"Inserted Day of Week", "MMM", each Text.Start([Month Name], 3), type text),
#"Inserted First Characters1" = Table.AddColumn(#"Inserted First Characters", "DDD", each Text.Start([Day Name], 3), type text),
#"Reordered Columns" = Table.ReorderColumns(#"Inserted First Characters1",{"Date", "Fin Year", "Month Name", "MMM", "Fin Month", "Day Name", "DDD", "Day of Week"}),
#"Added Custom" = Table.AddColumn(#"Reordered Columns", "YYMM", each ([Fin Year]-2000)*100 + [Fin Month]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"YYMM", Int64.Type}}),
#"Added Custom1" = Table.AddColumn(#"Changed Type1", "MonthID", each (Date.Year([Date]) - Date.Year(StartDate))*12 + Date.Month([Date])),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Custom1",{{"MonthID", Int64.Type}})
in
#"Changed Type2"
in
Custom3
quarter line from above code
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Quarter of Year","Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type),
when i tried this shows an error
Expression.Error: The name 'Inserted Quarter of Year' wasn't recognized. Make sure it's spelled correctly.
and also there is probelm when i rename "Fin Month " to only "Month" this shows also an error
how to resolve this

You have the syntax wrong and self referring to the column that you are trying to create, you need to reference the previous step.
Inserted Quarter of Year
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Quarter of Year","Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type),
should be:
#"Inserted Quarter of Year"= Table.AddColumn(#"Inserted Day Name", "Quarter of Year",each Date.QuarterOfYear([Date]),Int64.Type)
Hope that helps

Related

Power Query show Missing Payments split by Month and Year (MM YYYY)

I am trying to do the same as someone has already asked on a Microsoft forum
I am trying to show Payment info in Power BI but mainly what months/Years Payments have been missed.
I have 3 Tables, Date Table, Payment Table and Client Table.
The Payment Table has the fields,[Client ID],[Payment Id],[Payment Date], Client Table has fields [Client Id] and [Client Name] etc, Date Table has is generated using the min and max [Payment Date] from the Payment Table.
Is this possible in Power Query or using DAX in Power Bi and if so how?
Thanks
You can try something like this
code for new table, missing
let Source = Date,
#"Added Custom9" = Table.AddColumn(Source, "Month", each Date.Month([Date])),
#"Added Custom10" = Table.AddColumn(#"Added Custom9", "Year", each Date.Year([Date])),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom10",{"Date"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Columns1", {"Month", "Year"}),
#"Added Custom" = Table.AddColumn( #"Removed Duplicates", "Client ID", each Clients[Client ID]),
NewDates = Table.ExpandListColumn(#"Added Custom", "Client ID"),
#"Added Custom12" = Table.AddColumn(Payments, "Month", each Date.Month([Payment Date])),
NewPayments = Table.AddColumn(#"Added Custom12", "Year", each Date.Year([Payment Date])),
#"Merged Queries" = Table.NestedJoin(NewDates, {"Month","Year","Client ID"}, NewPayments, {"Month","Year","Client ID"}, "Payments", JoinKind.LeftOuter),
#"Added Custom1" = Table.AddColumn(#"Merged Queries", "Paid?", each Table.RowCount([Payments])),
#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([#"Paid?"] = 0)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Payments", "Paid?"}),
#"Merged Queries1" = Table.NestedJoin(#"Removed Columns", {"Client ID"}, Clients, {"Client ID"}, "Clients", JoinKind.LeftOuter),
#"Expanded Clients" = Table.ExpandTableColumn(#"Merged Queries1", "Clients", {"Client Name"}, {"Client Name"}),
#"Grouped Rows" = Table.Group(#"Expanded Clients", {"Month","Year"}, {
{"Missing Payments From", each Text.Combine(List.Transform([Client ID], Text.From), ","), type text},
{"Missing Payments From2", each Text.Combine(List.Transform([Client Name], Text.From), ","), type text}
})
in #"Grouped Rows"
remove the group step if you'd rather see the output in table format
Version 2 generates this:
//version2
let Source = Date,
#"Added Custom9" = Table.AddColumn(Source, "Month", each Date.Month([Date])),
#"Added Custom10" = Table.AddColumn(#"Added Custom9", "Year", each Date.Year([Date])),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom10",{"Date"}),
#"Removed Duplicates" = Table.Distinct(#"Removed Columns1", {"Month", "Year"}),
#"Added Custom" = Table.AddColumn( #"Removed Duplicates", "Client ID", each Clients[Client ID]),
NewDates = Table.ExpandListColumn(#"Added Custom", "Client ID"),
#"Added Custom12" = Table.AddColumn(Payments, "Month", each Date.Month([Payment Date])),
NewPayments = Table.AddColumn(#"Added Custom12", "Year", each Date.Year([Payment Date])),
#"Merged Queries" = Table.NestedJoin(NewDates, {"Month","Year","Client ID"}, NewPayments, {"Month","Year","Client ID"}, "Payments", JoinKind.LeftOuter),
#"Added Custom1" = Table.AddColumn(#"Merged Queries", "Paid?", each Table.RowCount([Payments])),
#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([#"Paid?"] = 0)),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Payments", "Paid?"}),
#"Merged Queries1" = Table.NestedJoin(#"Removed Columns", {"Client ID"}, Clients, {"Client ID"}, "Clients", JoinKind.LeftOuter),
#"Expanded Clients" = Table.ExpandTableColumn(#"Merged Queries1", "Clients", {"Client Name"}, {"Client Name"}),
#"Added Custom2" = Table.AddColumn(#"Expanded Clients", "MonthYear", each Text.From([Month])&"/"&Text.From([Year])),
#"Grouped Rows" = Table.Group(#"Added Custom2", {"Client ID","Client Name"}, {
{"Missing Payments", each Text.Combine(List.Transform([MonthYear], Text.From), ","), type text}
})
in #"Grouped Rows"

Adding random rows within a group in power bi

I would like to know how to create the last column, Audit. To determine whether it is Included or Not Included the sum of any rows in "Average meeting per Day" within the same Employee/Day should match the "Actual Meeting" the employee attended.
I've taken this as an Example dataset -
Further, use Group By and Conditional column to have the Audit added.
Group by -
Conditional Column -
Result -
Code -
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s3PS0msVNJRMgRiAz1TMGkEJBOVYnVwSBtjShuBJQzhZBJYOqQ0tRhZuwlcHqg9=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Day = _t, Emp_ID = _t, #"Actual Meeting" = _t, #"Average Meeting/Day" = _t, Emp_Name = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Day", type text}, {"Emp_ID", Int64.Type}, {"Actual Meeting", type number}, {"Average Meeting/Day", type number}, {"Emp_Name", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Day", "Emp_ID"}, {{"Sum of avg", each List.Sum([#"Average Meeting/Day"]), type nullable number}, {"Actual Meeting", each List.Min([Actual Meeting]), type nullable number}}),
#"Added Conditional Column" = Table.AddColumn(#"Grouped Rows", "Audit", each if [Actual Meeting] = [Sum of avg] then "Included" else "Not Included")
in
#"Added Conditional Column"
Not sure this is going to help, but here goes. Note: not set up to work with duplicate values among the potential items to analyze. No idea if it will work with so many decimals, so that the sum of the decimals might be 0.0000001 off from total and thus not be recognized. Works for me with whole numbers
let
Process=(x as table) as table =>
// Bill Szysz 2017, all combinations of items in list, blows up with too many items to process due to large number of combinations
let ComboList=x[AMD],
find=x[AM]{0},
Source=Table.FromList(List.Transform(ComboList, each Text.From(_))),
AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1),
ReverseIndeks = Table.AddIndexColumn(AddIndex, "RevIdx", Table.RowCount(AddIndex), -1),
Lists = Table.AddColumn(ReverseIndeks, "lists", each
List.Repeat(
List.Combine({
List.Repeat({[Column1]}, Number.Power(2,[RevIdx]-1)),
List.Repeat( {null}, Number.Power(2,[RevIdx]-1))
})
, Number.Power(2, [Index]))
),
ResultTable = Table.FromColumns(Lists[lists]),
#"Replaced Value" = Table.ReplaceValue(ResultTable,null,"0",Replacer.ReplaceValue,Table.ColumnNames(ResultTable )),
#"Added Index" = Table.AddIndexColumn(#"Replaced Value", "Index", 0, 1, Int64.Type),
totals = Table.AddColumn(#"Added Index", "Custom", each List.Sum(List.Transform(Record.ToList( Table.SelectColumns(#"Added Index",Table.ColumnNames(ResultTable )){[Index]}) , each Number.From(_)))),
#"Filtered Rows" = Table.SelectRows(totals, each ([Custom] = find)),
#"Kept First Rows" = Table.FirstN(#"Filtered Rows",1),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Kept First Rows", {"Custom", "Index"}, "Attribute", "Value"),
#"Filtered Rows1" = Table.SelectRows(#"Unpivoted Other Columns", each ([Value] <> "0")),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows1",{"Value"}),
FoundList = Table.TransformColumnTypes(#"Removed Other Columns",{{"Value", type number}}),
#"Merged Queries" = Table.NestedJoin(x, {"AMD"}, FoundList, {"Value"}, "output1", JoinKind.LeftOuter),
#"Expanded output1" = Table.ExpandTableColumn(#"Merged Queries", "output1", {"Value"}, {"Value"}),
#"Calculated Absolute Value" = Table.TransformColumns(#"Expanded output1",{{"Value", each if _=null then "Not Included" else "Included", type text}})
in #"Calculated Absolute Value",
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Day", type text}, {"Employee_ID", Int64.Type}, {"AM", Int64.Type}, {"AMD", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Day", "Employee_ID"}, {{"data", each _, type table [Day=nullable text, Employee_ID=nullable number, AM=nullable number, AMD=nullable number]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Process([data])),
#"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Day", "Employee_ID", "AM", "AMD", "Value"}, {"Day", "Employee_ID", "AM", "AMD", "Value"})
in
#"Expanded Custom"

How to add new column from calculation on two rows in power BI?

I have following table:
I want to add a new column "Total" using query editor(power Query) such that when "GL" is 'Gross Margin' then "Total" should be 'Gross Margin' on "Total India Market" multiplied by 'Total Net Sales' on "Total India Market" i.e 0.11*65687 and if "GL" is not 'Gross Margin' then "Total India Market"+"Export".
Desired output should look like below:
I do not want calculated column it should be in a query editor i.e power query.
You can achieve this using power query
First add an index column then calculate previous row for Total India Market and then add custom column to calculate total as per requirement
let
Source = Excel.Workbook(File.Contents("C:\Users\anumua2\Downloads\im_25_oct_21.xlsx"), null, true),
Data_Sheet = Source{[Item="Data",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Data_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"GL", type text}, {"Domestic Product", type number}, {"Total India Market", type number}, {"Export", type number}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
#"Prev" = Table.AddColumn(#"Added Index", "Custom", each #"Added Index"{[Index]-2}[#"Total India Market"]),
#"Renamed Columns" = Table.RenameColumns(Prev,{{"Custom", "Prev_Total India Market"}}),
#"Replaced Errors" = Table.ReplaceErrorValues(#"Renamed Columns", {{"Prev_Total India Market", 0}}),
#"Added Custom" = Table.AddColumn(#"Replaced Errors", "Custom", each if[GL] = "Gross Margin" then [Total India Market]*[Prev_Total India Market] else [Total India Market] + [Export]),
#"Renamed Columns1" = Table.RenameColumns(#"Added Custom",{{"Custom", "Total"}})
in
#"Renamed Columns1"
It seems to be that Total Net Sales is always on the row before Gross Margin.
If that is the case, then in order to multiply a value by the value in the same column preceding row, you'll need to either add an Index column, or, my preference because it calculates faster, add a "shifted column" where the value from the previous row is now on the same row.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZA/C4MwEMW/ijhLzWlyf0anTu2idBEHBykFacHY799LAqXELnnc8Xv3HhnHEkwNNVBZlZ33y14M7+2pw8kIR0FKE5VT9UsPr31ei6s6+nldvG6IBVXQIQegbZx1mem8vbwvLvN2f8QQaDCKiSEAeUh/68JhxxQ4JomX9eUv2fwrDwYCL2hMiuEMP7YPcMhCS6JqWxaTmQ7tQZLY+EWMGZ/a62EJHECb6oNzjrTQ9AE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, GL = _t, #"Domestic Product" = _t, #"Total India Market" = _t, Export = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"GL", type text},
{"Domestic Product", type number}, {"Total India Market", type number}, {"Export", type number}}),
//add a column = offset column from Total India Market
//This will calculate faster than using an INDEX column
offsetTotalIndiaMarket =
let
tbl = #"Changed Type",
ShiftedList = {null} & List.RemoveLastN(tbl[Total India Market]),
Custom1 = Table.ToColumns(tbl) & {ShiftedList}
in
Table.FromColumns(Custom1, Table.ColumnNames(tbl) & {"Shifted Tot India Market"}),
//add custom column to execute the described calculation
#"Added Custom" = Table.AddColumn(offsetTotalIndiaMarket, "Total", each
if [GL] = "Gross Margin"
then [Total India Market]*[Shifted Tot India Market]
else [Total India Market]+[Export]),
//Remove shifted column
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Shifted Tot India Market"})
in
#"Removed Columns"
Results
If it is NOT the case that Total Net Sales is always on the line preceding Gross Margin, then we can use a different algorithm. But also have to know if Gross Margin will always have a preceding Total Net Sales, or if we have to account for an inability to calculate also.
If this is the case, respond with a comment to this answer

New Calculated Table to Split Duration Hourly

i've got a datasheet with a bunch of tasks, their start/end time, duration and start day.
Task
Start Time
End Time
Duration
Start Day
Task1
21:00
22:15
1:15
Monday
Task1
21:20
23:30
2:10
Monday
Task2
23:00
23:20
0:20
Tuesday
What I'm trying to do is put this data into a new calculated table that would split each task and plot a new row for the mins spent in each hour, as determined by the duration. For example:
Task
Hour
Mins in Hour
Start Day
Task1
21
60
Monday
Task1
22
15
Monday
Task1
21
40
Monday
Task1
22
60
Monday
Task1
23
30
Monday
Task2
23
20
Tuesday
I'm having no luck, could anyone help please?
Can be done with PQ
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("tZg9bhwxDIXv4tqFSEkzs3uHVHFnuDCQVAGSwnCR20cSn2YkhtLsxk5FwP6WoB5/xNHz88PT69sPenh8YHf1TmxYknXuStk+vX9/+/b6++HlUVgWhgpL15ito2twY9a55jcO9oStMQQrBt+z7iJssZoN6W90UWcj+2xgS3zJMvzSxK+rLM7G1tk0i7PxJIbb/W5ytmoddBmwVHORc+746mjMOvh1Hn79iF2vIUK7KPr6YQwr/K435O3fWDkbzmiyC+JNdoVfHrOib7LwO9ZsQe0kPTbosI1ZB78BfoPl17M6XMDhsv3y6+eMdWDdLWybZJNtRLuc+T1Ei4iBJ2wVTdg0TCZsFa1rohM2RmGLPfOLZBRrshFnS5rVYh/6jfAbrwx9eahvw040y2FRQCoO1F+GqEQbJMqcNSPa+1FCrFILZAYQBXXw6tr+0RIodFa54Q63d7MerO/bUrElYSzTLttl7HYDgggYg5cM9CKoU6hVih3K/chT6NKjs0bXKDfD8QSdCFtQXAnZngVwFyopSChipXWIOniNmPnRQDn/jbCjZJYwkqwi2IQVv26qQdklWra9q3Uhlv9hZ0k2TJIrdxL2hWzrfWacTSRq2A3sZrC+YfNoKhNhMSdCaZxb/UbFznRYFDsbCoXFfpPYbi8dsOJ3m2tW2HW/ziSGtGsNYwCb7aR9enZDjsnOsWIdpo23rj4dwywXYB3YWV9olsHyp7Lbfp0E4zoRdpGc7r/BbjxgRYcF+5g9Hnr22B+tntdsjcHfEEOcrQA63vZbacDKrn3EEIzeZKCQV1LMsvbaqEMEVBUzKqdDawBkNrFGUefmjMz/iiq9ZKYXqFeolQWgFFuBcW/YqHiL07mg0boAGC2p0Fk3FBTLXbKxDsdRrFjD8rE2SSwb2SK463PgzRz07HxhEhYLU7Kzk2k2orriMF6vyiuY5SUsQzLee8yad5WVEuD+neOErfGO9W3YUx34yBvOZhV5ZV3s/UbjPtlZxEDreN79xU46XbPTT5MPsLO7p3tT2Fma6Ev7RCDUAxkzl/CVU22duWy0W1Aoj1Ncv53qUAyNNRZTdyyDs6ZYe9RfGjtH6zMWD1D2x1DEq0W5Lb++T9F2MVboRdB9LmBWFatQeY86WHneCGI1Sy1L+xsWGSFQeU9ETyYbWxE0u36AbXv9E9iqR5xkorIOfrs6Vmz4fyjJ0M22fUSzaoF2DQjaBkNbjdZeM0oBKFcU7RmtqmFhyxTdWZKXxBHrYNvbz2SdXNKJpVl2wZavH8bmfuK3vrB3L4mVffkD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Task " = _t, #"Start Time " = _t, #"End Time " = _t, #"Duration " = _t, #"Start Day" = _t]),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 1, 1, Int64.Type),
#"Changed Type" = Table.TransformColumnTypes(#"Added Index",{{"Task ", type text}, {"Start Time ", type time}, {"End Time ", type time}, {"Duration ", type time}, {"Start Day", type text}}),
#"Inserted Time Subtraction" = Table.AddColumn(#"Changed Type", "Subtraction", each [#"End Time "] - [#"Start Time "], type duration),
#"Added Custom" = Table.AddColumn(#"Inserted Time Subtraction", "Custom", each let x = Duration.TotalMinutes([Subtraction]),
y = if x<0 then x*-1 else x in y),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Times([#"Start Time "],[Custom],#duration(0,0,1,0))),
#"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom.1",{{"Custom.1", type time}}),
#"Inserted Hour" = Table.AddColumn(#"Changed Type1", "Hour", each Time.Hour([Custom.1]), Int64.Type),
#"Grouped Rows" = Table.Group(#"Inserted Hour", {"Index", "Hour"}, {{"min", each List.Min([Custom.1]), type nullable time}, {"max", each List.Max([Custom.1]), type nullable time}}),
#"Added Custom2" = Table.AddColumn(#"Grouped Rows", "Custom", each Duration.TotalMinutes([max] - [min])+1),
#"Merged Queries" = Table.NestedJoin(#"Added Index", {"Index"}, #"Added Custom2", {"Index"}, "Added Custom2", JoinKind.LeftOuter),
#"Expanded Added Custom2" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom2", {"Hour", "Custom"}, {"Hour", "Custom"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded Added Custom2",{"Task ", "Hour", "Custom", "Start Day"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Custom", "MinsInHours"}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"MinsInHours", Int64.Type}})
in
#"Changed Type2"
Edit
The same code will work with whatever row gets added
From here
To

Filter a column in Power Query so that it contains only the last date of each year

Can anyone please advise on how to filter this column in Power Query so that it contains only the last date of each year?
So, this should contain only 3 rows:
31/12/2019
31/12/2020
31/03/2021
Try this
Add custom column to pull out the year
= Date.Year([EndDate])
Add custom column to pull out the max date for each matching year
= (i)=>List.Max(Table.SelectRows(#"Added Custom" , each [Year]=i[Year]) [EndDate])
Add custom column to check the two dates against each other
= if [EndDate]=[MaxDate] then "keep" else "remove"
Filter on that column
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"EndDate", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([EndDate])),
#"Added Custom2" = Table.AddColumn(#"Added Custom","MaxDate",(i)=>List.Max(Table.SelectRows(#"Added Custom" , each [Year]=i[Year]) [EndDate]), type date ),
#"Added Custom1" = Table.AddColumn(#"Added Custom2", "Custom", each if [EndDate]=[MaxDate] then "keep" else "remove"),
#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom] = "keep"))
in #"Filtered Rows"
~ ~ ~
another way probably better for larger lists
Add custom column to pull out the year
= Date.Year([EndDate])
Group on year and take the Maximum of the EndDate Column
Merge that back to original data with left outer join and filter
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"EndDate", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([EndDate])),
#"Grouped Rows" = Table.Group(#"Added Custom", {"Year"}, {{"MaxDate", each List.Max([EndDate]), type date}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type",{"EndDate"}, #"Grouped Rows" ,{"MaxDate"},"Table2",JoinKind.LeftOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"MaxDate"}, {"MaxDate"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Table2", each ([MaxDate] <> null))
in #"Filtered Rows"
This is an older thread, but for those who are looking for the easiest solution, you can use :
= Table.SelectRows(#"Converted to Table", each [Date] = Date.EndOfYear( [Date] ) )
If you want to see the entire code in action, you can paste this in the advanced editor:
let
Source = List.Dates( #date( 2010, 1, 1), Duration.Days( #date( 2022, 12, 31) - #date( 2010, 1, 1 ) ) + 1 , #duration(1,0,0,0) ),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), type table[ Date = Date.Type ] , null, ExtraValues.Error),
#"Filtered Rows" = Table.SelectRows(#"Converted to Table", each [Date] = Date.EndOfYear( [Date] ))
in
#"Filtered Rows"
Hope that helps!
Rick de Groot
https://gorilla.bi