Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Dear community,
I have an employee list that is updated every month. Static stuff (employee ID, Name, Company entry and exit, gender etc.) are stored in a Dimension table and variable stuff (organisational unit,line manager, pay grade) in a fact table.
Now: How can I get entry and exit date into a dimension table with one row for each employee from an Excel table that has one entry per employee and month?
Source:
ID | Employee | Month/year | gender | org. unit | line manager | pay grade |
1 | John Doe | 03-2023 | male | … | ||
1 | John Doe | 04-2023 | male | |||
1 | John Doe | 05-2023 | male | |||
1 | John Doe | 06-2023 | male | |||
1 | John Doe | 07-2023 | male | |||
2 | Melissa Smith | 04-2023 | female | |||
2 | Melissa Smith | 05-2023 | female | |||
2 | Melissa Smith | 06-2023 | female | |||
2 | Melissa Smith | 07-2023 | female | |||
2 | Melissa Smith | 08-2023 | female | |||
3 | Tim Ding | 08-2023 | male |
Desired Dimension table output:
ID | Employee | Entry | Leave | gender |
1 | John Doe | 03-2023 | 07-2023 | male |
2 | Melissa Smith | 04-2023 | 08-2023 | female |
3 | Tim Ding | 08-2023 | 08-2023 | male |
I could get either entry or leave using GroupBy but not both.
I could duplicate the data, do GroupBy in each and then recombine them or put the months in the fact table and evaluate using DAX, but I believe there is a better way to do it in PowerQuery. Any idea?
Thanks!
Solved! Go to Solution.
try this code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKz8hTcMlPBTIv7Lmw4WKDnpExkJ2bmJOqFKuDqWbDhf0E1QDNubCTgJodF/su7CVCzW40NUZAjm9qTmZxcaJCcG5mScahBWjOSkslpBjJfYQVIzmUOMW7iVW84cKmC5sxFIO4IZm5Ci6ZeeloqiBqYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [D = _t, #"Employee " = _t, #"Month/year " = _t, #" gender " = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"D", Int64.Type}, {"Employee ", type text}, {"Month/year ", type date}, {" gender ", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"D", "Employee ", " gender "}, {{"min", each List.Min([#"Month/year "]), type nullable date}, {"max", each List.Max([#"Month/year "]), type nullable date}})
in
#"Grouped Rows"
try this code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfLKz8hTcMlPBTIv7Lmw4WKDnpExkJ2bmJOqFKuDqWbDhf0E1QDNubCTgJodF/su7CVCzW40NUZAjm9qTmZxcaJCcG5mScahBWjOSkslpBjJfYQVIzmUOMW7iVW84cKmC5sxFIO4IZm5Ci6ZeeloqiBqYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [D = _t, #"Employee " = _t, #"Month/year " = _t, #" gender " = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"D", Int64.Type}, {"Employee ", type text}, {"Month/year ", type date}, {" gender ", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"D", "Employee ", " gender "}, {{"min", each List.Min([#"Month/year "]), type nullable date}, {"max", each List.Max([#"Month/year "]), type nullable date}})
in
#"Grouped Rows"
to know how to solve the problem watch my video
https://1drv.ms/v/s!AiUZ0Ws7G26Rinnjq-TEMZIPsnG3?e=ypeziK
I cannot access it unfortunately. Access to onedrives is blocked by my employer
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
69 | |
60 | |
51 | |
36 | |
36 |
User | Count |
---|---|
84 | |
70 | |
58 | |
45 | |
44 |