Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
eliasayyy
Memorable Member
Memorable Member

if there is a new date for specific name, end date is new date m query

hello guys the title is a bit confusing but i will try to explain,
i have employee names i na table, with there effective date and pay

lets take example that next month, name B will quit and name A will stay but get a raise and name C will join: here is example of the table:

Name        Date            Pay
Name A12/1/2022500
Name A1/1/2023700
Name B12/1/2022400
Name B1/1/20230
Name C1/1/2023400
Name C1/16/2023500

 

what i want is in power query, i want to add a new column that is called end date, that says something like " if the name has a new date(max) this will be the end date for the previous period of the name, but if pay is 0, then same date and if its the latest day of the name, then end date is date.localnow()"

so desired result would be:

Name          Date             Pay         End Date
Name A12/1/20225001/1/2023
Name A1/1/2023700Today
Name B12/1/20224001/1/2023
Name B1/1/202301/1/2023
Name C1/1/20234001/3/2023
Name C1/3/2023500Today


is it possible?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Use Following PQ with 3 tables

 

PQ1: EmployeesPay Source

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI00jfUNzIwMgKyTQ0MlGJ1oOIQYWMg0xwq7ISm3ARZHKEcIuiMKghTCxE2hgmDbYwFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t, Pay = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Date", type date}, {"Pay", Int64.Type}})
in
#"Changed Type"

 

 

PQ2: EmployeesPay MaxDate

 

let
Source = #"EmployeesPay Source",
#"Grouped Rows" = Table.Group(Source, {"Name"}, {{"MaxDate", each List.Max([Date]), type nullable date}})
in
#"Grouped Rows"

 

 

PQ3: EmployeesPay FinalTable

 

let
Source = #"EmployeesPay Source",
#"Merged Queries" = Table.NestedJoin(Source, {"Name"}, #"EmployeesPay MaxDate", {"Name"}, "EmployeesPay MaxDate", JoinKind.LeftOuter),
#"Expanded EmployeesPay MaxDate" = Table.ExpandTableColumn(#"Merged Queries", "EmployeesPay MaxDate", {"MaxDate"}, {"MaxDate"}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded EmployeesPay MaxDate", "TerminateFlag", each if [Pay] = 0 then "Yes" else "No"),
#"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "isMaxDateRow", each if [Date] = [MaxDate] then "Yes" else "No"),
#"Changed Type" = Table.TransformColumnTypes(#"Added Conditional Column1",{{"TerminateFlag", type text}, {"isMaxDateRow", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "NewMaxDate", each if [TerminateFlag] = "Yes" or [isMaxDateRow] = "No" then [MaxDate] else DateTime.LocalNow()),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"NewMaxDate", type date}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"MaxDate", "TerminateFlag", "isMaxDateRow"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"NewMaxDate", "MaxDate"}})
in
#"Renamed Columns"

 

 

Result

 

shalinderverma_0-1672933867761.png

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Use Following PQ with 3 tables

 

PQ1: EmployeesPay Source

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI00jfUNzIwMgKyTQ0MlGJ1oOIQYWMg0xwq7ISm3ARZHKEcIuiMKghTCxE2hgmDbYwFAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t, Pay = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Date", type date}, {"Pay", Int64.Type}})
in
#"Changed Type"

 

 

PQ2: EmployeesPay MaxDate

 

let
Source = #"EmployeesPay Source",
#"Grouped Rows" = Table.Group(Source, {"Name"}, {{"MaxDate", each List.Max([Date]), type nullable date}})
in
#"Grouped Rows"

 

 

PQ3: EmployeesPay FinalTable

 

let
Source = #"EmployeesPay Source",
#"Merged Queries" = Table.NestedJoin(Source, {"Name"}, #"EmployeesPay MaxDate", {"Name"}, "EmployeesPay MaxDate", JoinKind.LeftOuter),
#"Expanded EmployeesPay MaxDate" = Table.ExpandTableColumn(#"Merged Queries", "EmployeesPay MaxDate", {"MaxDate"}, {"MaxDate"}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded EmployeesPay MaxDate", "TerminateFlag", each if [Pay] = 0 then "Yes" else "No"),
#"Added Conditional Column1" = Table.AddColumn(#"Added Conditional Column", "isMaxDateRow", each if [Date] = [MaxDate] then "Yes" else "No"),
#"Changed Type" = Table.TransformColumnTypes(#"Added Conditional Column1",{{"TerminateFlag", type text}, {"isMaxDateRow", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "NewMaxDate", each if [TerminateFlag] = "Yes" or [isMaxDateRow] = "No" then [MaxDate] else DateTime.LocalNow()),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"NewMaxDate", type date}}),
#"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"MaxDate", "TerminateFlag", "isMaxDateRow"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"NewMaxDate", "MaxDate"}})
in
#"Renamed Columns"

 

 

Result

 

shalinderverma_0-1672933867761.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.