cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Fran1991cesco
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:

 

Fran1991cesco_3-1674645299863.png

 

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
ITManuel
Helper V
Helper V

Hi @Fran1991cesco ,

 

create I measure and try the following code.

COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            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

View solution in original post

2 REPLIES 2
v-xinruzhu-msft
Community Support
Community Support

Hi @Fran1991cesco 

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))

vxinruzhumsft_0-1674808455797.png

 

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.

 

ITManuel
Helper V
Helper V

Hi @Fran1991cesco ,

 

create I measure and try the following code.

COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            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

Helpful resources

Announcements
Vote for T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Vote for your favorite t-shirt design now through March 28.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.

March Events 2023A

March 2023 Events

Find out more about the online and in person events happening in March!

Top Solution Authors