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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Maestro
Frequent Visitor

Sum of maximal value for specific name

Moving from (pivot)tables in Excel to Power BI provides some struggles. I will try to show my struggle as detailed as needed. The case: as a KPI (Key Performance Indicator) in sports I need to know from longitudinal data IF a player passed the benchmark or not (providing a % by dividing passed/all cases). He only needs to pass the benchmark once during the year (multiple matches obviously; benchmark can be different depending on playing position).

 

NameMatchTotal distance covered (m)Benchmark (m)Passed (o=no;1=yes)
Player A1600050001
Player B1400050000
Player C1700060001
Player D0 **1500--
Player A2550050001
Player B2400050000
Player C2500060000

** not enough playtime, so data is there, but not included for the KPI.

 

KPI = passed/total

In Excel I would insert a Pivot table on the table above and then use "Max of passed" providing for each player if he ever passed the benchmark and total amount of filled cells (so unique players in this pivot table). The pivot table in this example would look like:

NameMax of passed
Player A1
Player B0
Player C1

KPI: 2 out of 3=66.7%

Player D is not included in pivot table, since there is no valid data (0 or 1) Sum of Max of passed is needed, since 'just' sum of passed will provide 2 instead of 1 for player 1. 

 

In Power BI I provided a new measure  "amount_players" which is: DISTINCTCOUNT(query1[player]). This will show the amount of players that pass multiple filters (minimum of playing time, team and season). Now I need a measure "amount_passed" but using MAX(X), SUM or a combination does not deliver the right answer. The main struggle appears when a player is able to pass the benchmark for 3 matches; any use of sum wants to enter the player with a '3', but I only want to count him once. 

 

If I need to provide more context or sample data, please let me know! 

2 ACCEPTED SOLUTIONS
VahidDM
Super User
Super User

Hi @Maestro 

 

Please try this measure: [Edited]

 

amount_passed =
COUNTROWS (
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Passed] = 1 ),
        'Table'[Name],
        "pass", MAX ( 'Table'[Passed] )
    )
)

 

 

Did I answer your question? Mark my post as a solution!

Appreciate your Kudos VahidDM_0-1630033994438.png !!

View solution in original post

Thanks for your quick response @VahidDM. It does not work yet; the error (MdxScript(model)(10,80) that in the DAX formula they can't  compare Integer (pass yes, no or empty) with Text/String (player name). They suggest to use the VALUE or FORMAT function, but that would only work if I replace Name by a ID-number. Any suggestions to make it work while still using the playernames as strings? 

 

EDIT: it worked, after replacing the "1" with 1 as boolean expression within the FILTER: 

FILTER ( 'Table', 'Table'[Passed] = 1 ),

 Thanks!

View solution in original post

3 REPLIES 3
VahidDM
Super User
Super User

Hi @Maestro 

 

Please try this measure: [Edited]

 

amount_passed =
COUNTROWS (
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Passed] = 1 ),
        'Table'[Name],
        "pass", MAX ( 'Table'[Passed] )
    )
)

 

 

Did I answer your question? Mark my post as a solution!

Appreciate your Kudos VahidDM_0-1630033994438.png !!

Thanks for your quick response @VahidDM. It does not work yet; the error (MdxScript(model)(10,80) that in the DAX formula they can't  compare Integer (pass yes, no or empty) with Text/String (player name). They suggest to use the VALUE or FORMAT function, but that would only work if I replace Name by a ID-number. Any suggestions to make it work while still using the playernames as strings? 

 

EDIT: it worked, after replacing the "1" with 1 as boolean expression within the FILTER: 

FILTER ( 'Table', 'Table'[Passed] = 1 ),

 Thanks!

Happy to see you sorted it out. VahidDM_0-1630485682084.png !!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors