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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
RookiePowerBI19
New Member

Grand Total Sum of Last Year

Hi!

 

Need some basic assistance for an easy DAX command. Assume I have a table with 2 columns

'Sales'[Period] - Year and Month combined (202001, 202002 etc).

'Sales'[KG] - Numerical values in KG

 

Now assume I want to have a pivot table with Periods between 202201 and 202212 where I present the sales in KG for those periods but also last years sales ('Sales'[Period]-100). The difference between this year and last year in that column is 100 for each value. 

 

I've tried

Calculate(

SUM('Sales'[KG],

FILTER(

ALL['Sales'[Period]),

'Sales'[Period]=MAX('Sales'[Period])-100

)

)

 

This works great for all the individual Periods but not in the Grand Total. The Grand Total only shows the sum for the last individual value (202212).

 

Can anyone help out here? 

1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

Hi @RookiePowerBI19 

// Base measure
[Total KG] = SUM( 'Sales'[KG] )

// Derivative
[Total KG LY] = // last year's KG
    SUMX(
        DISTINCT( 'Sales'[Period] ),
        var IteratedPeriod = 'Sales'[Period]
        var KGLastYear = 
            CALCULATE(
                [Total KG],
                'Sales'[Period] = IteratedPeriod - 100
            )
        return
            KGLastYear
    )

Event though the above works, I would kindly warn you that this model should be changed asap as it's not correct. For correct models please consult this article: Understand star schema and the importance for Power BI … (bing.com)

View solution in original post

1 REPLY 1
daXtreme
Solution Sage
Solution Sage

Hi @RookiePowerBI19 

// Base measure
[Total KG] = SUM( 'Sales'[KG] )

// Derivative
[Total KG LY] = // last year's KG
    SUMX(
        DISTINCT( 'Sales'[Period] ),
        var IteratedPeriod = 'Sales'[Period]
        var KGLastYear = 
            CALCULATE(
                [Total KG],
                'Sales'[Period] = IteratedPeriod - 100
            )
        return
            KGLastYear
    )

Event though the above works, I would kindly warn you that this model should be changed asap as it's not correct. For correct models please consult this article: Understand star schema and the importance for Power BI … (bing.com)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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