Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Baseball Stats

I'd like some help summarizing baseball statistics utilizing a DAX expression to help me find the following

 

  • # H last 1 game / 3 games / 5 games
  • # AB last 1 game / 3 games / 5 games
  • Etc - might be RBI, PA.......
GPPAABH2B3BHRRBIRBBSOName
12222002100Player 1
12210000101Player 2
12210000000Player 3
22110000110Player 1
22210000101Player 2
22210001100Player 3
33220002210Player 1
32100000001Player 2
32210000100Player 3
42210001000Player 1
42200001001Player 2
41110001000Player 3
53000000330Player 1
53310000002Player 2
52210000000Player 3
63100000010Player 1
62200000002Player 2
62210001100Player 3
73210102201Player 1
73110000210Player 2
73210001100Player 3

1 Reply

  • 123abc's avatar
    123abc
    Community Champion

    To find the number of hits (H) and at-bats (AB) for each player in the last 1, 3, and 5 games, you can use the following DAX expressions:

    • H last 1 game: CALCULATE(SUM([H]), FILTER(ALL(Table), [GP] = MAX([GP])))
    • H last 3 games: CALCULATE(SUM([H]), FILTER(ALL(Table), [GP] >= MAX([GP]) - 2))
    • H last 5 games: CALCULATE(SUM([H]), FILTER(ALL(Table), [GP] >= MAX([GP]) - 4))
    • AB last 1 game: CALCULATE(SUM([AB]), FILTER(ALL(Table), [GP] = MAX([GP])))
    • AB last 3 games: CALCULATE(SUM([AB]), FILTER(ALL(Table), [GP] >= MAX([GP]) - 2))
    • AB last 5 games: CALCULATE(SUM([AB]), FILTER(ALL(Table), [GP] >= MAX([GP]) - 4))

    These expressions use the CALCULATE, SUM, FILTER, ALL, and MAX functions to calculate the total number of hits and at-bats for each player in the specified number of games. You can learn more about these functions from the DAX reference.

    You can use a similar approach to find other statistics such as RBI, PA, etc. For example, to find the RBI last 3 games, you can use:

    • RBI last 3 games: CALCULATE(SUM([RBI]), FILTER(ALL(Table), [GP] >= MAX([GP]) - 2))

    I hope this helps you with your baseball analysis. If you have any other questions, please feel free to ask. 😊