cancel
Showing results for
Did you mean: Frequent Visitor

## How to define a sum with a groupby

Hi all,

I am having a problem with a table just like to one that I show you here: At first I created a new column with the following formula:

``SUM = 'Table'[Hours Course 1] + 'Table'[Hours Course 2] + 'Table'[Hours Course 3]``

Then, I need to count the number of students that have done in total less then 15 hours, such as Student 4 an Student 3. For this I am using this formula:

``NumberOfStudent = CALCULATE( DISTINCTCOUNT('Table'[Name]), FILTER('Table', SUM('Table'[SUM]) < 15.00) ) ``

In the graphs that I have, the formula does not return the right number. Even if I remove the sum for the 'SUM' column, the result is off. Can someone help me please?

1 ACCEPTED SOLUTION  Helper V

create I measure and try the following code.

``````COUNTROWS (
FILTER (
SUMMARIZE ( 'Table', 'Table'[Name] ),
"SUM", CALCULATE ( SUM ( 'Table'[SUM] ) )
),
[SUM] < 15
)
)``````

This will give you the number of students with in total less than 15 hours.

Br

2 REPLIES 2  Community Support

You can refer to the following link.

You can modified your sum column:

``SUM = SUMX(FILTER('Table',[Name]=EARLIER('Table'[Name])),'Table'[Hours Course 1] + 'Table'[Hours Course 2] + 'Table'[Hours Course 3])``

Then

1.You can create a new column:

``NumberOfStudent = CALCULATE( DISTINCTCOUNT('Table'[Name]), FILTER('Table', [SUM]< 15.00) ) ``

2.You can create a new measure

``NumberOfStudents = CALCULATE(DISTINCTCOUNT('Table'[Name]),FILTER(ALLSELECTED('Table'),[SUM]<15))`` Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.  Helper V

create I measure and try the following code.

``````COUNTROWS (
FILTER (
SUMMARIZE ( 'Table', 'Table'[Name] ),
"SUM", CALCULATE ( SUM ( 'Table'[SUM] ) )
),
[SUM] < 15
)
)``````

This will give you the number of students with in total less than 15 hours.

Br  