Forum Discussion
towardhuzzahmo
2 years agoFrequent Visitor
Need Urgent Help W/ Power Query for HR Analysis
Hi, I'm a college student currently working on a non-school related project using Excel, Power BI, and Power Query. I've got a dataset I'm trying to make sense of and could really use some advice on...
towardhuzzahmo
2 years agoFrequent Visitor
Hi,
I would love if you could edit the code. That would be very helpful 🙂 The fiscal year runs from July 1 to June 30. I'm not quite sure what the seperation date should be greater than. But I think, it would be greater than July 1, 2015. If there are any other conditions that would be helpful for me to share, let me know. Thank you, thank you!
dufoq3
Community Champion
2 years agoTry this one. Edit 2nd step YourSource = Source and refer your data.
Logic: if employee worked at least 1 day in fiscal year then then 1 else 0.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rY/BDsIgDIZfhXBewjZdB0dNfAGvCwdUXBYJW2CL8e0tQozLPOkaSn+gfPnbNDTHAEEzetTtZJRDNWB6ZUdFjLIXPFwxC1ayQnBAiWtv1PmGtcyLCguhMvsJReYsWJFVYxGsxIagI5NDXc+YAXHq76azLWmd1jbdAXv9C7M9tMd95ztllwOvAoT4Dh9ORYgFeNR+THIbefzNO0yuH/QXj/+igruKbVKPlE8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Regular/Temporary" = _t, #"Full Time/Part Time" = _t, Location = _t, Sex = _t, #"Last Start" = _t, #"Manager#(lf)#(lf)(only mark yes if true)" = _t, Ethnicity = _t, #"Fiscal Year" = _t, #"Seperation Date" = _t]),
YourSource = Source,
CleanTrimColumnNames = Table.TransformColumnNames(YourSource, each Text.Trim(Text.Clean(_))),
ChangedTypeUS = Table.TransformColumnTypes(CleanTrimColumnNames,{{"Last Start", type date}, {"Fiscal Year", Int64.Type}, {"Seperation Date", type date}}, "en-US"),
FiscalYears = List.Buffer(List.Transform(List.Sort(List.Distinct(ChangedTypeUS[Fiscal Year])), Text.From)),
StepBack = ChangedTypeUS,
Ad_FiscalYearsAsColumns =
List.Accumulate(
FiscalYears,
StepBack,
(s,c)=> Table.AddColumn(s, c, each
if Date.Year([Last Start]) < Number.From(c) and ( [Seperation Date] = null or Date.Year([Seperation Date]) > Number.From(c) ) then 1 else
if [Last Start] >= #date(Number.From(c), 7, 1) or ( [Seperation Date] = null or [Seperation Date] >= #date(Number.From(c), 7, 1) ) then 1 else 0 )
),
GroupedRows = Table.Group(Ad_FiscalYearsAsColumns, {"Employee ID"}, {{"Details", each _, type table}}),
Ad_FiscalYearsAsColumns2 =
List.Accumulate(
FiscalYears,
GroupedRows,
(s,c)=> Table.AddColumn(s, c, each Record.Field(Table.Last(Table.SelectColumns([Details], c)), c), Int64.Type)
),
DetailsLastRow = Table.TransformColumns(Ad_FiscalYearsAsColumns2, {{"Details", Table.Last}}),
ExpandedDetails = Table.ExpandRecordColumn(DetailsLastRow, "Details", {"Regular/Temporary", "Full Time/Part Time", "Location", "Sex", "Last Start", "Manager(only mark yes if true)", "Ethnicity", "Seperation Date"}, {"Regular/Temporary", "Full Time/Part Time", "Location", "Sex", "Last Start", "Manager(only mark yes if true)", "Ethnicity", "Seperation Date"})
in
ExpandedDetails