Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply

how to calculate sum of a column excluding the last row

Hi All, 

 

I have a table, where the need the total of the Region column but need to exclude "Grand total" value from that sum. So just sum of anything before Grand Total.

 

 

mohiniverma2704_0-1722480937161.png

 

2 ACCEPTED SOLUTIONS
Thennarasu_R
Responsive Resident
Responsive Resident

Hi @mohiniverma2704 

Good Day !
First go to create the rank desc order based on Index column after that you should remoe the rank 1 . rank 1 will apper in last row .

Try this calculation for your requitrements

Measure =Var _AA=

RANKX(ALL(Table name ),CALCULATE(SUM(Index column),,Desc)
Return
Calculate(sum(Output Column),__AA<>1)

Thanks,
Thennarasu R

View solution in original post

v-tangjie-msft
Community Support
Community Support

Hi @mohiniverma2704 ,

 

Thanks to @Thennarasu_R  and @netanel  for their quick replies. Please allow me to offer an alternative idea:

(1) This is my test data.

vtangjiemsft_0-1722566123298.png

(2) We can create a measure.

MEASURE =
IF (
    ISFILTERED ( 'Table'[Region] ),
    SUM ( 'Table'[Value] ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Region] <> "Grand total" )
    )
)

Or if you are limited to excluding the last row, then we need to click on "transform data" to go to the power query and add an index column.

vtangjiemsft_2-1722566572081.png

 

Then we can create a measure.

Measure 2 = 
var _max_row=MAXX(ALL('Table'),[Index])
RETURN IF(ISFILTERED('Table'[Region]),SUM('Table'[Value]),CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),[Index] <> _max_row)))

vtangjiemsft_1-1722566530753.png

Best Regards,

Neeko Tang

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

View solution in original post

3 REPLIES 3
v-tangjie-msft
Community Support
Community Support

Hi @mohiniverma2704 ,

 

Thanks to @Thennarasu_R  and @netanel  for their quick replies. Please allow me to offer an alternative idea:

(1) This is my test data.

vtangjiemsft_0-1722566123298.png

(2) We can create a measure.

MEASURE =
IF (
    ISFILTERED ( 'Table'[Region] ),
    SUM ( 'Table'[Value] ),
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALLSELECTED ( 'Table' ), [Region] <> "Grand total" )
    )
)

Or if you are limited to excluding the last row, then we need to click on "transform data" to go to the power query and add an index column.

vtangjiemsft_2-1722566572081.png

 

Then we can create a measure.

Measure 2 = 
var _max_row=MAXX(ALL('Table'),[Index])
RETURN IF(ISFILTERED('Table'[Region]),SUM('Table'[Value]),CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),[Index] <> _max_row)))

vtangjiemsft_1-1722566530753.png

Best Regards,

Neeko Tang

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

Thennarasu_R
Responsive Resident
Responsive Resident

Hi @mohiniverma2704 

Good Day !
First go to create the rank desc order based on Index column after that you should remoe the rank 1 . rank 1 will apper in last row .

Try this calculation for your requitrements

Measure =Var _AA=

RANKX(ALL(Table name ),CALCULATE(SUM(Index column),,Desc)
Return
Calculate(sum(Output Column),__AA<>1)

Thanks,
Thennarasu R
netanel
Post Prodigy
Post Prodigy

Hi @mohiniverma2704 

This one should work

Sum_Without_Grand_Total =
IF(
ISINSCOPE('Yure_Table'[SomeColumn]),
SUM('Yure_Table'[Amount]),
BLANK()
)








Did I answer your question?
Mark my post as a solution!
Appreciate your Kudos!

Connect on Linkedin
linkedin.com/in/netanel-shriki

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.