Forum Discussion

kkassel's avatar
kkassel
Frequent Visitor
2 years ago
Solved

visual showing max value for each year with corresponding name

I have a set of data where I'm trying to create a table or matrix that shows the max value of a given year and the corresponding name of the person.  This data is NBA stats. I want to be able to show the player in each season with the highest points per game. With the table sorted in season order. Below I have a small sample set and then what I want the visual to display.

Sample Data:

YearPlayerGames PlayedPointsPts per G
2016James Harden82237629.0
2017Russell Westbrook81255831.6
2017James Harden81235629.1
2015James Harden81221727.4
2016Stephen Curry79237530.1
2017Isaiah Thomas76219928.9
2017Anthony Davis75209928.0
2016Kevin Durant72202928.2
2015LeBron James69174325.3
2015Anthony Davis68165624.4
2015Russell Westbrook67188628.1
2015Kevin Durant2768625.4

 

Visual Result:

YearPlayerPts per G
2015Russell Westbrook28.1
2016Stephen Curry30.1
2017Russell Westbrook31.6

 

  • Hi,

    Try these measures

    PPG = MAX(Data[Pts per G])
    Pl = CONCATENATEX(TOPN(1,VALUES(Data[Player]),[PPG]),Data[Player],", ")

    Hope this helps.

     

  • Hi,

    This M code works as well

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZHLasMwEEV/RXgdjDWyHl62zaKvVVvoImShEoFNE6lIdiB/X80oIY4hG4lBZ+7cudpsKmi4qlbVqz24xJ5t3DmfSwP5AKHxCbpquyJQ5+pjSsnt9+zbpfEnhvCLNEdMSpMvwWs155fChApZhGt+QeU9FEgFdN1eUGz9HN1f7zx7mmI85Vp3xS/KiOYqi70vyQ62Z199ONiELM3mHbWY+ma7Bz/2wZ/Y2h4HYlEQmjM7d/DmjoNn6ylaPyJIgTVwFoX5Xu/uMQbPaL1cKmS4bgWFVos5upyvMFKuSlztNQN55ycULsGNUcXGTbwLx6BJXxUXWXn7Dw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Player = _t, #"Games Played" = _t, Points = _t, #"Pts per G" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Player", type text}, {"Games Played", Int64.Type}, {"Points", Int64.Type}, {"Pts per G", type number}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Year"}, {{"Pl", each Table.Max(_,"Player")}, {"Max", each List.Max([Pts per G]), type nullable number}}),
        #"Expanded Pl" = Table.ExpandRecordColumn(#"Grouped Rows", "Pl", {"Player"}, {"Player"}),
        #"Sorted Rows" = Table.Sort(#"Expanded Pl",{{"Year", Order.Ascending}})
    in
        #"Sorted Rows"

    Hope this helps.

     

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi kkassel 

     

    ThxAlot Ashish_Mathur  GOOD ANSWER!

     

    I have another method.

     

    You can create a measure.

     

    Measure = 
    VAR _max = CALCULATE(MAX([Pts per G]), ALLEXCEPT('Table', 'Table'[Year]))
    RETURN
    IF( MAX([Pts per G]) = _max, 1, 0) 

     

     

    Put the measure into the visual-level filters, set up show items when the value is 1.

     

    Best Regards,
    Yulia Xu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Hi,

    Try these measures

    PPG = MAX(Data[Pts per G])
    Pl = CONCATENATEX(TOPN(1,VALUES(Data[Player]),[PPG]),Data[Player],", ")

    Hope this helps.

     

  • Hi,

    This M code works as well

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dZHLasMwEEV/RXgdjDWyHl62zaKvVVvoImShEoFNE6lIdiB/X80oIY4hG4lBZ+7cudpsKmi4qlbVqz24xJ5t3DmfSwP5AKHxCbpquyJQ5+pjSsnt9+zbpfEnhvCLNEdMSpMvwWs155fChApZhGt+QeU9FEgFdN1eUGz9HN1f7zx7mmI85Vp3xS/KiOYqi70vyQ62Z199ONiELM3mHbWY+ma7Bz/2wZ/Y2h4HYlEQmjM7d/DmjoNn6ylaPyJIgTVwFoX5Xu/uMQbPaL1cKmS4bgWFVos5upyvMFKuSlztNQN55ycULsGNUcXGTbwLx6BJXxUXWXn7Dw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Player = _t, #"Games Played" = _t, Points = _t, #"Pts per G" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Player", type text}, {"Games Played", Int64.Type}, {"Points", Int64.Type}, {"Pts per G", type number}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"Year"}, {{"Pl", each Table.Max(_,"Player")}, {"Max", each List.Max([Pts per G]), type nullable number}}),
        #"Expanded Pl" = Table.ExpandRecordColumn(#"Grouped Rows", "Pl", {"Player"}, {"Player"}),
        #"Sorted Rows" = Table.Sort(#"Expanded Pl",{{"Year", Order.Ascending}})
    in
        #"Sorted Rows"

    Hope this helps.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi kkassel 

     

    ThxAlot Ashish_Mathur  GOOD ANSWER!

     

    I have another method.

     

    You can create a measure.

     

    Measure = 
    VAR _max = CALCULATE(MAX([Pts per G]), ALLEXCEPT('Table', 'Table'[Year]))
    RETURN
    IF( MAX([Pts per G]) = _max, 1, 0) 

     

     

    Put the measure into the visual-level filters, set up show items when the value is 1.

     

    Best Regards,
    Yulia Xu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.