# Show the wining ratio

**URL:** <https://forum.bubble.io/t/show-the-wining-ratio/230277>\
**Category:** Database\
**Created:** [October 28, 2022, 3:22pm UTC](https://forum.bubble.io/t/show-the-wining-ratio/230277 "2022-10-28T15:22:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![theronyuen](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@theronyuen](https://forum.bubble.io/u/theronyuen)\
**Post date:** [October 28, 2022, 3:22pm UTC](https://forum.bubble.io/t/show-the-wining-ratio/230277/1 "2022-10-28T15:22:32Z")

</div>

Hi, I created a private lobby for game, and I want to show the user current winning ratio.

The below is my database setup:  
Game Lobby: Text  
Player Team A/B: List of User  
Winning Team: Text

 ![Database](https://us1.discourse-cdn.com/bubble/original/3X/b/b/bbf7bc6bb32e5c36bbe37ea9cd9c882273cdde26.jpeg)

These 3 users played 2 games in the same lobby.  
Peter winning ratio: 100% as he wins 2 games  
John winning ratio: 50% as he wins 1 game  
Steve winning ratio: 0% as he wins 0 game

my question is:

1. The database created the same lobby for two times, so I suppose somehow I can retrieve the data that how many games they played in the same lobby?

2: how can I make this calculation and display it?  
Winning Ratio = User Winning Game / Total Game in Same Lobby

Thanks a lot

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [October 28, 2022, 10:51pm UTC](https://forum.bubble.io/t/show-the-wining-ratio/230277/2 "2022-10-28T22:51:10Z")

</div>

Hi there, @theronyuen… I’m pretty sure what you are trying to accomplish would be a lot easier if a team is a thing (data type) that has a field for a team name and a field that is a list of users, and a game has fields to store a list of teams and a winning team. That being said, is there a particular reason why you have the data type set up as you are showing?

Best…  
Mike

---

<div class="post-metadata">

**Author:** ![theronyuen](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@theronyuen](https://forum.bubble.io/u/theronyuen)\
**Post date:** [October 29, 2022, 1:15am UTC](https://forum.bubble.io/t/show-the-wining-ratio/230277/3 "2022-10-29T01:15:11Z")

</div>

Hi, Mike,

Yes, that’s because it’s for team basketball internal challenge, and user could be sometimes Team A , sometimes Team B, and people usually have multiple games in different team in one day. It’s like we having a group of friends, maybe 12-15 people go to play basketball, 5 vs 5, will have multiple games in one day, and end up everyone will have different teammate every game right? so if I ask them to build a new team every time, it could be lots of work on database?

So I currently using a custom state to allow them to choose their own Team A / B \> Show up in a repeating group to separate Team A / B \> Game start (Button) \> Pick the Winner Team (Button) \> Ask for Rematch or Leave Lobby (Pop Out)

if they choose to rematch, the page will refresh, then everyone will be in the same lobby, and then they can choose team A/B again and go for second game.

I was hoping that I could get the result when the day is done to see who has the highest / lowest wining ratio. Thanks

Best regard  
Theron

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [October 29, 2022, 9:54am UTC](https://forum.bubble.io/t/show-the-wining-ratio/230277/4 "2022-10-29T09:54:06Z")

</div>

For what it’s worth, I played around for a good amount of time with trying to get the win ratio using your current setup, and I kept hitting dead ends. That being said, I’m still not convinced that I couldn’t hack something together that produces the desired result, but the key word there is hack because it would definitely be hacky.

So, I am pretty firmly in the camp of you needing to change your set up. I would probably have data types called `Lobby`, `Game`, and `Team`. A lobby would have a list of games, games would have a list of teams and a winning team. and a team would have a list of users. With a more “structured” set up in place, I think it will be much easier to do what you are trying to do.

---

<div class="post-metadata">

**Author:** ![theronyuen](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@theronyuen](https://forum.bubble.io/u/theronyuen)\
**Post date:** [October 30, 2022, 8:39am UTC](https://forum.bubble.io/t/show-the-wining-ratio/230277/5 "2022-10-30T08:39:41Z")

</div>

Thanks, problem is solved for now, and yes… its hacky.

I use the Math Expression Formula Calculator Plugin to do the math “Search for Game :filtered (Winner Team contain Current Cell’s User) :count / Search for Game :filtered (User in Game contain Current Cell’s User):count”

I also changed the data type to 3 list of user (Winner Team, Loser Team, User in Game) instead of Team A, Team B, Winner (text)… Because I think no one care they were on Team A or B, since they swap teammate all the time.

Thank you for helping out.
