Forum Discussion
JanoLehocky
4 years agoHelper I
Help with identifying increase within a date range group
Good evening Power BI community, Hoping someone can help me with this challenge that I would like to proper and elegant solution for. I am starting with data that looks like this: Person...
- 4 years ago
Jakinta - replied to you
JanoLehocky
4 years agoHelper I
I just noticed the dates were not formatted right in the second table:
| Personnel no. | Personnel Name | Salary Band | Reason on Pay Record | Basic Pay Record Start Date | PROMO STATUS | PROMO CYCLE |
| 123 | Jean-Luc Picard | 12 | Merit Review | 03/01/2019 | ||
| 123 | Jean-Luc Picard | 13 | Promotion | 03/01/2020 | Promotion | On Cycle |
| 123 | Jean-Luc Picard | 13 | Other | 10/19/2020 | ||
| 123 | Jean-Luc Picard | 13 | Other | 11/06/2020 | ||
| 234 | Benjamin Sisco | 10 | Merit Review | 03/01/2019 | ||
| 234 | Benjamin Sisco | 11 | Merit Review | 03/01/2020 | Promotion | On Cycle |
| 234 | Benjamin Sisco | 11 | Promotion | 06/25/2021 | ||
| 3434534 | Thomas Riker | 10 | Other | 01/01/2019 | ||
| 3434534 | Thomas Riker | 10 | Merit Review | 03/01/2019 | ||
| 3434534 | Thomas Riker | 10 | Other | 01/01/2020 | ||
| 3434534 | Thomas Riker | 10 | Merit Review | 03/01/2020 | ||
| 3434534 | Thomas Riker | 10 | Other | 01/01/2021 | ||
| 666667 | Travis Mayweather | 8 | Other | 02/04/2019 | ||
| 666667 | Travis Mayweather | 9 | Other | 11/03/2019 | ||
| 666667 | Travis Mayweather | 10 | Other | 07/01/2020 | Promotion | Off Cycle |
- Jakinta4 years agoSolution Sage
Although I am not quite sure why your Desired Output table is not following the rule
1. Where/when the actual promotions are happening. (a promo is an increase in salary band),
you can give a try to the code below:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ndJdC4IwFAbgvzK8Nraz2Ye3XUZSVHfhxbBBK9xgWtG/bzOhZfiVF8IOezznPXg8BkBZEAYrwdVkfcvQVmbcnGwFqH0lwsgS7cRdioc9EoYJYEogDtKwg7ry1uhcl1Irz1HS7zblWRh3IBjisQYwmX0MZZEtLoW68FwqtJdFpqsv9yZrk9Aue3pCcyV2zqljUDEWsWha0cNZ57xAO3mt1+Dls438KbtRd8JxDetwfzUcZH8avtcyc8/cGcPvskAJfz4Er+8ufEcxiT7pOl3c+GPYQPc9qJcufQE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Personnel no." = _t, #"Personnel Name" = _t, #"Salary Band" = _t, #"Reason on Pay Record" = _t, #"Basic Pay Record Start Date" = _t]), Grouped = Table.Group(Source, {"Personnel no."}, {{"Gr", each let t=_ in Table.AddColumn( Table.AddColumn( Table.AddIndexColumn(t, "i",-1,1), "PROMO STATUS", each try if Number.From([#"Salary Band"]) > Number.From(t[#"Salary Band"]{[i]}) then "Promotion" else "" otherwise ""), "PROMO CYCLE", each if [#"PROMO STATUS"]="" then "" else if Date.Month(Date.From([#"Basic Pay Record Start Date"])) =3 then "On Cycle" else "Off Cycle" ), type table }}), Removed = Table.RemoveColumns(Grouped,{"Personnel no."}), FINAL = Table.ExpandTableColumn(Removed, "Gr", List.RemoveItems (Table.ColumnNames(Removed[Gr]{0}), {"i"})) in FINALResult:
- JanoLehocky4 years agoHelper I
Jakinta - replied to you
- JanoLehocky4 years agoHelper I
Figured this out with a work colleague! Thank you so much Jakinta!!!
Cheers
Jano