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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
bitofanewb
Frequent Visitor

Help with complex problem needing done in M, DAX or SQL

Hi,

 

I need to create a column called Current Pot, whose output says 'Yes' or 'No'. 

 

I have 3 columns that can be used to help create this: TraineeID (unique number given to each trainee when they start a course), Pot (the pot number they are on - this starts at 1 when they've joined the course, goes upto 2 if they go on a break or withdraw, 3 if they return from a break etc... the highest we currently have is 10, but this could be higher in future), and URN (concatenation of TraineeID and Pot without a space or punctuation - done in SQL).

 

In order to state it's their Current Pot, I need to select only the highest Pot of each TraineeID, which can change with time.

 

Does anyone know how I could go about this, please?

 

Any help would be greatly appreciated - thank you for reading.

 

** Please let me know if I need to try and explain this better, or you require more information.

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

GroupBy Trainee and Aggregate by Max of Pot

Then Join with  ungrouped table and transform the non-empty tables to Yes

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WijBU0lEyVIrVgTKNIEwjhKgRQtQYIWqMKmqMMMEYIWoCYZogtJmgWoGkzVQpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Trainee = _t, Pot = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Trainee", type text}, {"Pot", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "URN", each [Trainee]&Number.ToText([Pot],"00"), type text),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Trainee"}, {{"Max Pot", each List.Max([Pot]), type nullable number}}),

    #"Merge" = Table.NestedJoin(#"Added Custom",{"Trainee","Pot"}, #"Grouped Rows",{"Trainee","Max Pot"},"Is Max Pot", JoinKind.LeftOuter),
    #"Is Max" = Table.TransformColumns(#"Merge",{"Is Max Pot", each if Table.IsEmpty(_) then null else "Yes", type nullable text})
in
    #"Is Max"

 

Before

ronrsnfld_0-1741609934736.png

 

After

ronrsnfld_1-1741609977883.png

 

 

 

View solution in original post

2 REPLIES 2
ronrsnfld
Super User
Super User

GroupBy Trainee and Aggregate by Max of Pot

Then Join with  ungrouped table and transform the non-empty tables to Yes

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WijBU0lEyVIrVgTKNIEwjhKgRQtQYIWqMKmqMMMEYIWoCYZogtJmgWoGkzVQpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Trainee = _t, Pot = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Trainee", type text}, {"Pot", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "URN", each [Trainee]&Number.ToText([Pot],"00"), type text),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Trainee"}, {{"Max Pot", each List.Max([Pot]), type nullable number}}),

    #"Merge" = Table.NestedJoin(#"Added Custom",{"Trainee","Pot"}, #"Grouped Rows",{"Trainee","Max Pot"},"Is Max Pot", JoinKind.LeftOuter),
    #"Is Max" = Table.TransformColumns(#"Merge",{"Is Max Pot", each if Table.IsEmpty(_) then null else "Yes", type nullable text})
in
    #"Is Max"

 

Before

ronrsnfld_0-1741609934736.png

 

After

ronrsnfld_1-1741609977883.png

 

 

 

Hey, 

 

Thank you so much for your help. 

 

With a couple of very minor tweaks it did the job:

 

#"Grouped Rows" = Table.Group(#"Added Custom89", {"TRAINEEID"}, {{"Max Pot", each List.Max([Pot]), type nullable number}}),
#"Merge" = Table.NestedJoin(#"Added Custom89",{"TRAINEEID","Pot"}, #"Grouped Rows",{"TRAINEEID","Max Pot"},"Is Max Pot", JoinKind.LeftOuter),
#"Expanded Is Max Pot" = Table.ExpandTableColumn(Merge, "Is Max Pot", {"Max Pot"}, {"Max Pot"}),
#"Added Custom92" = Table.AddColumn(#"Expanded Is Max Pot", "Current Pot", each if [Max Pot] = null then "No" else "Yes")
in
#"Added Custom92"

 

Thanks again.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.