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
AnonymousUK
Regular Visitor

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 9
v-lili6-msft
Community Support
Community Support

hi  @AnonymousUK 

"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

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Fowmy
Super User
Super User

@AnonymousUK 

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
 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.

@AnonymousUK 

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.

 

Fowmy_0-1601320201499.png

________________________

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

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Apologies for the delay in replying to you. Thank you for your support regarding this. Hopefully I can explain more clearly what I require. Please see the below example data:

 

RaceNameCountryTimeLeg
100mName 2A60.901
100mName 2A60.841
100mName 2A60.551
100mName 2A61.321
100mName 2A60.001
100mName 2A61.001
50mName 2A27.001
50mName 2A27.001
100mName 2A61.001
100mName 2A60.001
100mName 3A62.401
50mName 7A27.841
50mName 2A27.712
50mName 2A27.892
50mName 2A27.622
50mName 2A27.872
50mName 5A30.452
100mName 6A68.452
100mName 6A69.452
50mName 9A32.452
50mName 1A26.453
50mName 5A26.453
50mName 6A32.023
100mName 8A59.453
100mName 8A59.453
50mName 9A32.363
50mName 1A25.774
100mName 1A54.444
100mName 1A54.314
100mName 1A54.774
100mName 1A54.454
100mName 1A53.454
100mName 1A54.454
50mName 4A25.314
50mName 4A25.184
50mName 4A25.264
50mName 4A25.194
50mName 4A25.184
100mName 4A54.654
100mName 4A54.214
100mName 4A53.454
50mName 4A24.454
50mName 4A24.454

 

The outcome I require is the fastest team per country per race using one athlete per leg. There are four legs of the race.

 

I have used the Advanced Group By function on race, country and leg with the following operation minimum time. I get the following output:

RaceNameCountryTimeLeg
100mName 2A60.001
100mName 6A68.452
100mName 8A59.453
100mName 1A53.454
50mName 2A27.001
50mName 2A27.712
50mName 1A26.453
50mName 4A24.454

 

The issue I have is with the 50m race and athlete 'Name 2' for legs 1 and 2 (highlighted above). Only one athlete can perform one leg and I need the fastest time for each leg (as long as the athlete doesn't performed another leg).

 

I have used the Advanced Group By function using the following variables: Race, Country and Athlete. I used the minimum operation for the variable 'Time' to give me the fastest time for each athlete per race and country. I then did another Advanced Group By function using the following variables: Race, Country and Leg. This gave me the following output:

RaceNameCountryTimeLeg
100mName 2A60.001
100mName 6A68.452
100mName 8A59.453
100mName 1A53.454
50mName 2A27.001
50mName 1A26.453
50mName 4A25.184

 

The issue with the above is that there are only three athletes for the race 50m. Using the Advanced Group By function on Race, Country and Athlete resulted in no athletes for leg 2 (these athletes had faster times for other legs).

 

I require the following output:

RaceNameCountryTimeLeg
100mName 2A60.001
100mName 6A68.452
100mName 8A59.453
100mName 1A53.454
50mName 7A27.841
50mName 2A27.622
50mName 1A26.453
50mName 4A24.454

 

The above output is the fastest combination for country A for the 100m and the 50m races. For the 50m race the above output has taken the fastest times for leg 2,3 and 4. For Leg 1 a slower time has been taken because the fastest time was that of the athlete with the fastest time for leg 2. If the fastest time for leg 1 was used and the fastest time of another athlete for leg 2 the combination would have been slower.

 

How do I obtain the above? Will it require IF statements of some sort?

 

Thank you.

@AnonymousUK 

Name 2 has recorded the fastest time both in Leg 1 and 2 for the same race. To pick the fastest for Leg 1, you drop Name 2 though he has fastest in it because he recorded the best time in leg 2.

What would be the logic to apply here?

________________________

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



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Apologies, I am not sure I understand your question regarding the logic? 

 

The logic needs to be that the fastest combination is always selected for each country and race.

 

The fastest athlete for each leg needs to be selected however, if the athlete performs another leg then the next fastest time for another athlete must be selected. The fastest combination overall must be selected which is why the required output is as follows:

 

RaceNameCountryTimeLeg
100mName 2A60.001
100mName 6A68.452
100mName 8A59.453
100mName 1A53.454
50mName 7A27.841
50mName 2A27.622
50mName 1A26.453
50mName 4A24.454

 

I need athlete 'Name 2' to swim leg 2 rather leg 1 because this means that the overall time for all four athletes for 'Country A' for the 50m race is the fastest (overall time of 01:46.36) . If athlete 'Name 2' had performed leg 1 then I would have the following output which is a slower overall time (overall time of 01:48.40).

 

RaceNameCountryTimeLeg
100mName 2A60.001
100mName 6A68.452
100mName 8A59.453
100mName 1A53.454
50mName 2A27.001
50mName 5A30.52
50mName 1A26.453
50mName 4A24.454

 

Does there need to be an IF statement in the code? How do I code to get the above outcomes?

 

Thank you.

amitchandak
Super User
Super User

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

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.

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.