List of users with the highest sum of points - laravel

I would like to create a ranking ordered by the user who has the most "points" scored.
My "points" table has these fields: user_id, type and quantity.
In this example, user 1 has a total of 4 points, while user 2 has a total of 8.
My dilemma after several unsuccessful tests, is to create a cycle that shows users with the highest sum of "quantity".
How can I do?

you need to use selectRaw(sum(columan) as total) then group
Point::selectRaw("SUM(quantity) as total_quantity,user_id")->groupBy('user_id')->get()

Related

Counting values generated by a Matrix in SSRS

I have created a matrix report that has a Row Group of Person and a column group of Subject with Child groups of SubmittedBy and Grading Name. The data that is being pulled through is a mixture of numerical and alphabetic data. I am needing to do a count per row of how many of a certain criteria appear. For example, I wish to count by person how many 1's they have achieved, or how many A* they have achieved (this is all grading data from a school). Is there a way to do this with matrix data?
If there is a way, can you then get a count using certain criteria, for example, if grading Name = focus count how many WB grades there are per person (row)?
This is the Design
This shows a subsection of data (as it is a very large dataset), but with SchoolID, Forename and Surname cut off to preserve anonymity.
A simple way would be to add Total to the Subject row group and use the count() function:
[

How to summarize by calculated measure in Power BI?

I have transactional data which contains customer information as well as stores they shopped from. I can count the number of different stores each customer used by a simple DISTINCTCOUNT([Site Name]) measure.
There are millions of customers and I want to make a simple summary table which shows the sum of # customers who visited X number of stores. Like a histogram. Maximum stores they visited is 6, minimum is 1.
I know there are multiple ways to do this but I am new to DAX and can't do what I think yet.
The easiest way:
Assuming your DISTINCTCOUNT([Site Name]) measure is called CustomerStoreCount ...
Add a new dimension table, StoreCount, to your model containing a single column, StoreCount. Populate it with the values 1,2,3,4,5,6 (... up to maximum number of stores.)
Create a measure, ThisStoreCount = MAX(StoreCount[StoreCount]).
Create a base customer count measure, TotalCustomers:=DISTINCTCOUNT(CustomerTable[Customer])
Create a contextual measure, CustomersWhoVisitedXNumberOfStores := CALCULATE ( TotalCustomers, FILTER(VALUES(CustomerTable[Customer]), ThisStoreCount = CustomerStoreCount) )
On your pivot table / reporting tool, etc. use StoreCount[StoreCount] on the axes and CustomersWhOVisitedXNumberOfStores as the measure.
So basically walk through the customer list (since there's no relationship between StoreCount and CustomerTable), compare that customer's CustomerStoreCount with the maximum StoreCount[StoreCount] value, which for each StoreCount[StoreCount] value is ... drum roll itself. If it matches, keep it, otherwise filter it out; you end up with a count of customers whose store visits equals the value of StoreCount[StoreCount].
And of course the more general modeling hint: when you want to display a metric by something (i.e. customer count by number of stores visited), that something is an attribute, not a metric.

Adding summary for group section in crystal report

I am designing a report in which I filter the data and then add a group. I also add a summary field to show the sum of the cost of items in the group. But The amount of sum is not correct, it shows the sum of all items in the group without considering the criteria to filter the data (It sum the cost of all item). However, in the group I have 5 items and the sum should show the sum of cost for these 5 items not all items. But If I use the running total for the cost, it shows the right amount. How can I solve the problem in using the summary field?
Are you putting the summary field in the group footer? A running total field in CR will come up with different sums depending on where you put it in the report, so you have to be a bit careful.

Sorting a group into sub groups based on two characteristics

I think I have a moderately useful solution but really curious if anyone has a better way. I'm also unsure how to properly define the type of problem I have, which means I haven't done much Googling.
The problem:
I have an unknown number of players who are selecting roles for a game. Valid roles are 1-5. The players MUST select a primary role, but they also have an option for a secondary role. The options for their secondary role are "none", one of 1-5 (different from their primary), or "any". I must then put players into teams of 5, each team requires one of each number. The goal is to maximize the number of correctly formed teams.
My current solution:
Divide players into 3 groups: A) People who selected "none" as their secondary, B) People who selected a number as their secondary, C) people who selected "any" s their secondary
Fill up teams with players from group A, placing them as their primary role.
Count the number of open positions remaining in the existing, non-full teams
Count the number roles represented by group B (both primary and secondary)
Based on the count of open positions, start adding players from group B - the order for filling positions is biggest deficit to smallest deficit, with a preference to picking players who have as their other role a number with the biggest size (by representation) in group B
Fill in the left overs with group C
If worse came to worse I could always just throw people into groups regardless of their preferred role, but ideally I would create correct groups.
Do primary and secondary roles have the same bearing on team balance? If so, you could look at the problem from the point of the teams and the status of each team's current roles/needs.
For example, the first person on team A may be both 1 and 3, so team A has a 1 and a 3. The next person on team A should not be a 1 or a 3 in either the primary or secondary role. Using the remaining team needs (roles 2,4,5) you can iterate through the possible members until either 1) the team is filled/balanced or 2) there are no remaining candidates.
Is there more to the problem? I get the feeling I'm not getting the whole issue.

random group generator in R

I have a data set consisting of 250 students from different schools and classrooms. For the experimental design, I would like to generate in a random manner 35 groups consisting of approx. 7 students in each group, and then after the first activity, break up the students as randomly as possible in to 25 groups of 10 students each. Is there a package and example of how I can perform this in R?
If there's no relation between which groups students are in during the first and second activities, then it's the same problem twice over.
Assuming a student can only belong to one group at a time, just shuffle the array and pull out elements per your group size until there are no more left.
students=1:250;
rand_students=sample(students,length(students));

Resources