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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ALGH08
Frequent Visitor

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 1
123abc
Community Champion
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. 😊

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.