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.
Hello community!
So I am looking to create a new column that is based on Individual Client IDS and the first known date of the assessment. I am hoping to take these two variables and then the end goal be "Initial" or "reassessment" as the new column labels based on each Client. However, I'm finding it hard to figure out exactly how to create this code for this.
So what I have now is this:
The end goal would look like this:
Any help would be greatly appreciated! Thank you!
Solved! Go to Solution.
You can group by ClientID and take the min over the date column to find the Initial dates. Then merge that back with the original query and add a custom column that returns different results if the date equals the initial date.
Here's a full sample query you can paste into the Advanced Editor of a new blank query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VczLCQAgEAPRXnIWYlZFrUW2/zb8HcTrg5kxIASIirSoDg9XGtMC0wFbkKkfKmWvSfsili0N7hM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ClientID = _t, LastPRAPAREDate = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ClientID", Int64.Type}, {"LastPRAPAREDate", type date}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ClientID"}, {{"InitialDate", each List.Min([LastPRAPAREDate]), type nullable date}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ClientID"}, #"Grouped Rows", {"ClientID"}, "Grouped Rows", JoinKind.LeftOuter),
#"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"InitialDate"}, {"InitialDate"}),
#"Added Custom" = Table.AddColumn(#"Expanded Grouped Rows", "AssementType", each if [LastPRAPAREDate] = [InitialDate] then "Initial" else "Reassessment", type text)
in
#"Added Custom"
You can group by ClientID and take the min over the date column to find the Initial dates. Then merge that back with the original query and add a custom column that returns different results if the date equals the initial date.
Here's a full sample query you can paste into the Advanced Editor of a new blank query:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VczLCQAgEAPRXnIWYlZFrUW2/zb8HcTrg5kxIASIirSoDg9XGtMC0wFbkKkfKmWvSfsili0N7hM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ClientID = _t, LastPRAPAREDate = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ClientID", Int64.Type}, {"LastPRAPAREDate", type date}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ClientID"}, {{"InitialDate", each List.Min([LastPRAPAREDate]), type nullable date}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"ClientID"}, #"Grouped Rows", {"ClientID"}, "Grouped Rows", JoinKind.LeftOuter),
#"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"InitialDate"}, {"InitialDate"}),
#"Added Custom" = Table.AddColumn(#"Expanded Grouped Rows", "AssementType", each if [LastPRAPAREDate] = [InitialDate] then "Initial" else "Reassessment", type text)
in
#"Added Custom"
That worked like a charm!!! Thanks so much!!!
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 |
---|---|
15 | |
11 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
9 | |
7 | |
6 |