Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Group By

Good Afternoon,

 

Please see the below section of my data which has been anonymised:

RaceNameCountryTimeLeg
50mAA25.764
50mAA26.453
50mBA26.991
50mBA27.712
50mBA27.892
50mBA27.622
50mCA27.872
50mCA25.314
50mCA25.184
50mCA25.264
50mCA25.194
50mCA25.184
50mDA24.454
50mDA24.454
50mEA30.442
50mFA26.453
50mGA32.023
50mGA27.831
50mHA32.452
50mHA32.353


I need to group the data by the following columns: Race, Country, Name and Leg. The aggregation needs to show the minimum time for each Leg (1,2,3 and 4).

 

I have used the Group by function in Power BI however, this leaves me with the following example for one country and one race:

 

RaceNameCountryTimeLeg
50mBA26.991
50mBA23.622
50mAA26.453
50mDA24.454

 

As you can see from the above table the same athlete is shown for Leg 1 and 2. The output needs to be the fastest times for each leg but with the athletes only appearing once in the relay team.

 

How do I group the data ensuring the fastest times are taken but the athletes are not duplicated across the legs?

 

Thank you.

 

9 Replies

  • Anonymous , In this case Min(Table[Time]) should have worked with other columns in table or Matrix

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you.

       

      Apologies I am not sure I understand. I am a beginner at Power BI. I am using the transform data window to conduct my queries and the data is in a table.

       

      Will the query Min(Table[Time]) ensure the fastest time per leg and only one athlete per leg?

       

      Thank you.

  • Anonymous 

    I think you need to summarize excluding the Leg to the min for each player across all legs.

     

    New Table = 
    VAR _T = 
    SUMMARIZECOLUMNS(
    	'TABLE'[Race],
    	'TABLE'[Country],
    	'TABLE'[Name],
    	"_Min", min(Table[Time])
    	)
    RETURN
    _T

     

    ________________________

    If my answer was helpful, please consider Accept it as the solution to help the other members find it

    Click on the Thumbs-Up icon if you like this reply 🙂

    YouTube  LinkedIn
     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you.

      I have tried this code in the formula box at the top in power query editor and it did not work. I have tried it in the normal window of Power BI and it has returned some data however, it only provides me the fastest time for each athlete not each leg. I was already able to do this using the Group By function. This is not what I need, please see the original post as I need to ensure I have the fastes time per leg without having the same athlete competing on more than one leg.

      Also what type of code is this that I am using? Why did it not work in the power query editor?

      Thank you.

      • Fowmy's avatar
        Fowmy
        Super User

        Anonymous 

        As per your sample data, Name B has appeared in leg 1 and 2 and each leg has a min of 26.99 and 27.62, so it appears twice. Now, Which line do want to show? 26.99?


        Provide expected results based on your sample so I can work it out based on the understanding of the logic.

         



        ________________________

        If my answer was helpful, please consider Accept it as the solution to help the other members find it

        Click on the Thumbs-Up icon if you like this reply 🙂

        YouTube  LinkedIn

         

  • v-lili6-msft's avatar
    v-lili6-msft
    Community Support

    hi  Anonymous 

    "I need to group the data by the following columns: Race, Country, Name and Leg."

    for athlete "B", he has two leg, so in this case it should have two row data, 

    do you mean you just want to show only one row data that is fastest time "23.62" ?

    Race Name Country Time Leg
    50m B A 26.99 1
    50m B A 23.62 2

     

    please share your expected output based on your sample data, that will be a great help.

     

    Regards,

    Lin