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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
user9394
Microsoft Employee
Microsoft Employee

can't get column total with sumx

Why is this not working? I'm trying to get  returnRate*big total.  the grand total is not adding up.

user9394_0-1668549554350.png

final = 

var bigtotal = [total_new_qty]/CALCULATE([total_new_qty], ALLSELECTED('dataset'[group]))
var returnRate  = ([total_cost]/[old_total_qty])
var prod = returnRate*bigtotal
return SUMX(VALUES('dataset'[group]), prod)
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @user9394 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1668566197611.png

Please try:

 

final =
VAR _a =
    SUMMARIZE (
        'dataset',
        'dataset'[group],
        "Rate",
            CALCULATE (
                SUM ( 'dataset'[cost] ),
                FILTER ( ALL ( 'dataset' ), [group] = EARLIER ( 'dataset'[group] ) )
            )
                / CALCULATE (
                    SUM ( 'dataset'[oldqty] ),
                    FILTER ( ALL ( 'dataset' ), [group] = EARLIER ( 'dataset'[group] ) )
                ),
        "BigTotal",
            CALCULATE (
                SUM ( 'dataset'[totaqty] ),
                FILTER ( ALL ( 'dataset' ), [group] = EARLIER ( 'dataset'[group] ) )
            )
                / CALCULATE ( SUM ( 'dataset'[totaqty] ), ALL ( 'dataset' ) )
    )
RETURN
    SUMX ( _a, [BigTotal] * [Rate] )

 Final output:

vjianbolimsft_1-1668566222939.png

If this measure can't work, please provide more details about the other measures that you used and your source data after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

5 REPLIES 5
v-jianboli-msft
Community Support
Community Support

Hi @user9394 ,

 

This is caused by a very important concept in dax - context.
EARLIER is mainly used in the context of a computed column, it returns the current value of the specified column and evaluates the column externally.

 

For more details, please refer to:

EARLIER function (DAX) - DAX | Microsoft Learn

Context in DAX Formulas - Microsoft Support 

 

Best Regards,

Jianbo Li

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

v-jianboli-msft
Community Support
Community Support

Hi @user9394 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1668566197611.png

Please try:

 

final =
VAR _a =
    SUMMARIZE (
        'dataset',
        'dataset'[group],
        "Rate",
            CALCULATE (
                SUM ( 'dataset'[cost] ),
                FILTER ( ALL ( 'dataset' ), [group] = EARLIER ( 'dataset'[group] ) )
            )
                / CALCULATE (
                    SUM ( 'dataset'[oldqty] ),
                    FILTER ( ALL ( 'dataset' ), [group] = EARLIER ( 'dataset'[group] ) )
                ),
        "BigTotal",
            CALCULATE (
                SUM ( 'dataset'[totaqty] ),
                FILTER ( ALL ( 'dataset' ), [group] = EARLIER ( 'dataset'[group] ) )
            )
                / CALCULATE ( SUM ( 'dataset'[totaqty] ), ALL ( 'dataset' ) )
    )
RETURN
    SUMX ( _a, [BigTotal] * [Rate] )

 Final output:

vjianbolimsft_1-1668566222939.png

If this measure can't work, please provide more details about the other measures that you used and your source data after removing sensitive data.

 

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

 

It works!  Can you explain why it works? what is "earlier" and why are there two calculate functions for each virtual column that is created?

amitchandak
Super User
Super User

@user9394 , Try

 

final =

var bigtotal = [total_new_qty]/CALCULATE([total_new_qty], ALLSELECTED('dataset'[group]))
var returnRate = ([total_cost]/[old_total_qty])
var prod = returnRate*bigtotal
return SUMX(VALUES('dataset'[group]), calculate(prod))

Or Two measure approach


final =

var bigtotal = [total_new_qty]/CALCULATE([total_new_qty], ALLSELECTED('dataset'[group]))
var returnRate = ([total_cost]/[old_total_qty])
var prod = returnRate*bigtotal
return prod


final Sum = SUMX(VALUES('dataset'[group]),[final])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

the first approach gives me the correct row toal, but not the grand total

user9394_0-1668571309360.png



The second approach gives me the grand total, but not the row total

user9394_1-1668571353460.png

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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