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
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
Responsive Resident
Responsive Resident

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
Responsive Resident
Responsive Resident

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