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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
AllanBerces
Post Prodigy
Post Prodigy

MAX Date

HI can anyone help me on my PQ, on my table we required the max date on each Job no.

AllanBerces_0-1763595923900.png

DESIRED OUTPUT

AllanBerces_1-1763595966236.png

JOB No.POD
XXXX22672/28/2026
XXXX22672/13/2026
XXXX22671/28/2026
XXXX226711/13/2025
XXXX22678/29/2025
TTTTT22692/28/2026
TTTTT22692/13/2026
TTTTT22691/28/2026
TTTTT22698/29/2025
YYY22814/3/2026
YYY22812/28/2026
YYY22812/13/2026
YYY22811/28/2026
YYY228112/23/2025
YYY228111/13/2025
YYY22816/27/2025
SVV22882/13/2026
SVV22881/28/2026
SVV228811/25/2025
RTE229011/13/2025
RTE229012/19/2025
RTE229011/17/2025
RTE22908/29/2025
QQQQ287911/17/2025
QQQQ28798/29/2025
KL288111/17/2025
KL28818/29/2025
WU288211/17/2025
WU28828/29/2025
QMK22422/13/2026
QMK22421/28/2026
QMK224211/21/2025
QMK224211/13/2025
QMK22426/27/2025
QMK22422/13/2026
3 ACCEPTED SOLUTIONS
MasonMA
Community Champion
Community Champion

Hi,

 

you can use the M code based on this logic.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZFLDoMwDETvkjVS8PBJcoCuaBdtKS1C3P8adaUK20nI8j2PB5ltcx9+wBhc4+ARPVqMbm8yQV1V0FmC6B8ZcsPzScT8e2xSUW+N7teGTjO2Z11XIBLz3qtVgm255lSdp5N54kVdrTe7iIjRIwh/LgvzWDQLt82Ksxhk0WO+AKktm5XginSWCDVhj3rnhxhSmVDGRqYrfyyVgYPb8feLMcrxg2cfdJuAHsXxhNvjKc6Caouy44mwv63avH8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"JOB No." = _t, POD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"JOB No.", type text}, {"POD", type date}}),
    #"Grouped" = Table.Group(#"Changed Type", {"JOB No."}, {{"Detail", each _, type table}}),
    #"Added Max POD" = Table.AddColumn(#"Grouped", "Max POD", each List.Max([Detail][POD])),
    #"Expanded Detail" = Table.ExpandTableColumn(#"Added Max POD", "Detail", {"POD"}, {"POD"}),
    #"Added POD_MaxOnly" = Table.AddColumn(#"Expanded Detail", "POD_MaxOnly", each if [POD] = [Max POD] then [POD] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added POD_MaxOnly",{"POD", "Max POD"})
in
    #"Removed Columns"

 

View solution in original post

PhilipTreacy
Super User
Super User

Hi @AllanBerces 

 

Download PBIX file with the code shown below

 

Please note that I'm using dd/mm/yyyy in the images below but this code will work fine for you with mm/dd/yyyy.

 

To get exactly the output you asked for is actually quite tricky.  You could group the rows by Job No. and then extract the Max POD date but you will run into a couple of issues.

 

First for the job RTE2290, the max date will be on the 2nd row, but your desired result shows all the max dates on the first row for each job.:

 

PhilipTreacy_0-1763604552927.png

 

You will also end up with 2 dates showing for the QMK2242 job because it has 2 entries that are the max date

 

PhilipTreacy_1-1763604611709.png

 

To get the desired result you said you wanted, you need to first group by Job No. but I have then sorted the POD column in the table that results from that grouping.  So dates are sorted from most recent, for example for the QMK2242 job you get this

 

PhilipTreacy_2-1763605030370.png

 

We only need the date from the first row, otherwsie you could end up with 13/02/2026 being shown twice.  So I blank all the dates in the other rows

 

= Table.TransformColumns(
    Grouped,
    {
        {"Detail",
            each
                let
                    t = Table.AddIndexColumn(_, "idx", 0, 1),
                    t2 = Table.AddColumn(t, "POD2", each if [idx] = 0 then [POD] else ""),
                    t3 = Table.RemoveColumns(t2, {"POD", "idx"}),
                    t4 = Table.RenameColumns(t3, {{"POD2", "POD"}})
                in
                    t4
        , type table}
    }
)

 

PhilipTreacy_3-1763605148729.png

 

I can then delete the Job No. column and extract the data from the Detail column

 

PhilipTreacy_4-1763605195895.png

 

Here's the full code which you can download from the link above.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZFLDoMwDETvkjVS8PBJcoCuaBdtKS1C3P8adaUK20nI8j2PB5ltcx9+wBhc4+ARPVqMbm8yQV1V0FmC6B8ZcsPzScT8e2xSUW+N7teGTjO2Z11XIBLz3qtVgm255lSdp5N54kVdrTe7iIjRIwh/LgvzWDQLt82Ksxhk0WO+AKktm5XginSWCDVhj3rnhxhSmVDGRqYrfyyVgYPb8feLMcrxg2cfdJuAHsXxhNvjKc6Caouy44mwv63avH8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"JOB No." = _t, POD = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"POD", type date}}, "en-US"),
    #"Grouped" = Table.Group(
        #"Changed Type with Locale",
        {"JOB No."},
        {{"Detail", each Table.Sort(_, {{"POD", Order.Descending}}), type table}}
    ),
    #"Added Custom" = Table.TransformColumns(
    Grouped,
    {
        {"Detail",
            each
                let
                    t = Table.AddIndexColumn(_, "idx", 0, 1),
                    t2 = Table.AddColumn(t, "POD2", each if [idx] = 0 then [POD] else ""),
                    t3 = Table.RemoveColumns(t2, {"POD", "idx"}),
                    t4 = Table.RenameColumns(t3, {{"POD2", "POD"}})
                in
                    t4
        , type table}
    }
),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"JOB No."}),
    #"Expanded Detail" = Table.ExpandTableColumn(#"Removed Columns", "Detail", {"JOB No.", "POD"}, {"JOB No.", "POD"})
in
    #"Expanded Detail"

 

Regards

 

Phil

 

 

 

 

 

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

ronrsnfld
Super User
Super User

Here's another method, adding a column to the JOB group where only the first entry has the Final POD:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZFLDoMwDETvkjVS8PBJcoCuaBdtKS1C3P8adaUK20nI8j2PB5ltcx9+wBhc4+ARPVqMbm8yQV1V0FmC6B8ZcsPzScT8e2xSUW+N7teGTjO2Z11XIBLz3qtVgm255lSdp5N54kVdrTe7iIjRIwh/LgvzWDQLt82Ksxhk0WO+AKktm5XginSWCDVhj3rnhxhSmVDGRqYrfyyVgYPb8feLMcrxg2cfdJuAHsXxhNvjKc6Caouy44mwv63avH8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"JOB No." = _t, POD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"JOB No.", type text}, {"POD", type date}}),
    
    #"Group JOBs" = Table.Group(#"Changed Type","JOB No.",{
        {"Final POD", each {List.Max([POD])}&List.Repeat({null},Table.RowCount(_)-1), 
            type {nullable date}}
                }),
    
    #"Expanded Final POD" = Table.ExpandListColumn(#"Group JOBs", "Final POD")
in
    #"Expanded Final POD"

View solution in original post

4 REPLIES 4
ronrsnfld
Super User
Super User

Here's another method, adding a column to the JOB group where only the first entry has the Final POD:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZFLDoMwDETvkjVS8PBJcoCuaBdtKS1C3P8adaUK20nI8j2PB5ltcx9+wBhc4+ARPVqMbm8yQV1V0FmC6B8ZcsPzScT8e2xSUW+N7teGTjO2Z11XIBLz3qtVgm255lSdp5N54kVdrTe7iIjRIwh/LgvzWDQLt82Ksxhk0WO+AKktm5XginSWCDVhj3rnhxhSmVDGRqYrfyyVgYPb8feLMcrxg2cfdJuAHsXxhNvjKc6Caouy44mwv63avH8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"JOB No." = _t, POD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"JOB No.", type text}, {"POD", type date}}),
    
    #"Group JOBs" = Table.Group(#"Changed Type","JOB No.",{
        {"Final POD", each {List.Max([POD])}&List.Repeat({null},Table.RowCount(_)-1), 
            type {nullable date}}
                }),
    
    #"Expanded Final POD" = Table.ExpandListColumn(#"Group JOBs", "Final POD")
in
    #"Expanded Final POD"
PhilipTreacy
Super User
Super User

Hi @AllanBerces 

 

Download PBIX file with the code shown below

 

Please note that I'm using dd/mm/yyyy in the images below but this code will work fine for you with mm/dd/yyyy.

 

To get exactly the output you asked for is actually quite tricky.  You could group the rows by Job No. and then extract the Max POD date but you will run into a couple of issues.

 

First for the job RTE2290, the max date will be on the 2nd row, but your desired result shows all the max dates on the first row for each job.:

 

PhilipTreacy_0-1763604552927.png

 

You will also end up with 2 dates showing for the QMK2242 job because it has 2 entries that are the max date

 

PhilipTreacy_1-1763604611709.png

 

To get the desired result you said you wanted, you need to first group by Job No. but I have then sorted the POD column in the table that results from that grouping.  So dates are sorted from most recent, for example for the QMK2242 job you get this

 

PhilipTreacy_2-1763605030370.png

 

We only need the date from the first row, otherwsie you could end up with 13/02/2026 being shown twice.  So I blank all the dates in the other rows

 

= Table.TransformColumns(
    Grouped,
    {
        {"Detail",
            each
                let
                    t = Table.AddIndexColumn(_, "idx", 0, 1),
                    t2 = Table.AddColumn(t, "POD2", each if [idx] = 0 then [POD] else ""),
                    t3 = Table.RemoveColumns(t2, {"POD", "idx"}),
                    t4 = Table.RenameColumns(t3, {{"POD2", "POD"}})
                in
                    t4
        , type table}
    }
)

 

PhilipTreacy_3-1763605148729.png

 

I can then delete the Job No. column and extract the data from the Detail column

 

PhilipTreacy_4-1763605195895.png

 

Here's the full code which you can download from the link above.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZFLDoMwDETvkjVS8PBJcoCuaBdtKS1C3P8adaUK20nI8j2PB5ltcx9+wBhc4+ARPVqMbm8yQV1V0FmC6B8ZcsPzScT8e2xSUW+N7teGTjO2Z11XIBLz3qtVgm255lSdp5N54kVdrTe7iIjRIwh/LgvzWDQLt82Ksxhk0WO+AKktm5XginSWCDVhj3rnhxhSmVDGRqYrfyyVgYPb8feLMcrxg2cfdJuAHsXxhNvjKc6Caouy44mwv63avH8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"JOB No." = _t, POD = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"POD", type date}}, "en-US"),
    #"Grouped" = Table.Group(
        #"Changed Type with Locale",
        {"JOB No."},
        {{"Detail", each Table.Sort(_, {{"POD", Order.Descending}}), type table}}
    ),
    #"Added Custom" = Table.TransformColumns(
    Grouped,
    {
        {"Detail",
            each
                let
                    t = Table.AddIndexColumn(_, "idx", 0, 1),
                    t2 = Table.AddColumn(t, "POD2", each if [idx] = 0 then [POD] else ""),
                    t3 = Table.RemoveColumns(t2, {"POD", "idx"}),
                    t4 = Table.RenameColumns(t3, {{"POD2", "POD"}})
                in
                    t4
        , type table}
    }
),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"JOB No."}),
    #"Expanded Detail" = Table.ExpandTableColumn(#"Removed Columns", "Detail", {"JOB No.", "POD"}, {"JOB No.", "POD"})
in
    #"Expanded Detail"

 

Regards

 

Phil

 

 

 

 

 

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy @MasonMA @ronrsnfld thank you very much for the reply work as i need

MasonMA
Community Champion
Community Champion

Hi,

 

you can use the M code based on this logic.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZFLDoMwDETvkjVS8PBJcoCuaBdtKS1C3P8adaUK20nI8j2PB5ltcx9+wBhc4+ARPVqMbm8yQV1V0FmC6B8ZcsPzScT8e2xSUW+N7teGTjO2Z11XIBLz3qtVgm255lSdp5N54kVdrTe7iIjRIwh/LgvzWDQLt82Ksxhk0WO+AKktm5XginSWCDVhj3rnhxhSmVDGRqYrfyyVgYPb8feLMcrxg2cfdJuAHsXxhNvjKc6Caouy44mwv63avH8B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"JOB No." = _t, POD = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"JOB No.", type text}, {"POD", type date}}),
    #"Grouped" = Table.Group(#"Changed Type", {"JOB No."}, {{"Detail", each _, type table}}),
    #"Added Max POD" = Table.AddColumn(#"Grouped", "Max POD", each List.Max([Detail][POD])),
    #"Expanded Detail" = Table.ExpandTableColumn(#"Added Max POD", "Detail", {"POD"}, {"POD"}),
    #"Added POD_MaxOnly" = Table.AddColumn(#"Expanded Detail", "POD_MaxOnly", each if [POD] = [Max POD] then [POD] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added POD_MaxOnly",{"POD", "Max POD"})
in
    #"Removed Columns"

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.