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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Lyle
Frequent Visitor

Measure from current month & year, to the same month from the previous year

I'm trying to create a DAX measure for the growth percentage like this:

 

Lyle_0-1638192142441.png

 

I have data for 3 years but when using filters in PBI for Trade 1 and Trade 2 I can't figure out the formula.

 

Is this possible?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Lyle ,

I think you don't need to add an index column to calculate the growth rate. You can try my measure.

Growth =
VAR _Current =
    SUM ( Box[Trips] )
VAR _LASTYEAR =
    CALCULATE (
        SUM ( Box[Trips] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year]
                = MAX ( 'Calendar'[Year] ) - 1
                && 'Calendar'[Month] = MAX ( 'Calendar'[Month] )
        )
    )
VAR _DIFF = _Current - _LASTYEAR
VAR _GROWTH =
    DIVIDE ( _DIFF, _LASTYEAR )
VAR _MINDATE =
    EOMONTH ( MINX ( ALL ( Box ), Box[ETA] ), 11 )
VAR _MAXDATE =
    EOMONTH ( MAXX ( ALL ( Box ), Box[ETA] ), 0 )
RETURN
    IF (
        MAX ( 'Calendar'[Date] ) <= _MINDATE
            || MAX ( 'Calendar'[Date] ) > _MAXDATE,
        BLANK (),
        _GROWTH
    )

Here I use mindate (2019/12/31 the last day of first year) and maxdate(2021/11/30 the last day of current month) as a filter in IF function, we will get growth in dates between the range, out the range will show blank.

1.png

 

Best Regards,
Rico Zhou

 

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

7 REPLIES 7
Anonymous
Not applicable

Hi @Lyle ,

I think you don't need to add an index column to calculate the growth rate. You can try my measure.

Growth =
VAR _Current =
    SUM ( Box[Trips] )
VAR _LASTYEAR =
    CALCULATE (
        SUM ( Box[Trips] ),
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Year]
                = MAX ( 'Calendar'[Year] ) - 1
                && 'Calendar'[Month] = MAX ( 'Calendar'[Month] )
        )
    )
VAR _DIFF = _Current - _LASTYEAR
VAR _GROWTH =
    DIVIDE ( _DIFF, _LASTYEAR )
VAR _MINDATE =
    EOMONTH ( MINX ( ALL ( Box ), Box[ETA] ), 11 )
VAR _MAXDATE =
    EOMONTH ( MAXX ( ALL ( Box ), Box[ETA] ), 0 )
RETURN
    IF (
        MAX ( 'Calendar'[Date] ) <= _MINDATE
            || MAX ( 'Calendar'[Date] ) > _MAXDATE,
        BLANK (),
        _GROWTH
    )

Here I use mindate (2019/12/31 the last day of first year) and maxdate(2021/11/30 the last day of current month) as a filter in IF function, we will get growth in dates between the range, out the range will show blank.

1.png

 

Best Regards,
Rico Zhou

 

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

Thanks @Anonymous ! Absolutley spot on. Wow this is amazing. Thank you so much.

smpa01
Super User
Super User

@Lyle  you can achieve what you need with this, pbix is attached

Measure =
VAR _00 =
    MAX ( 'Table'[Count] )
VAR _0 =
    CALCULATE (
        CALCULATE ( MAX ( 'Table'[Count] ), 'Table'[Count] < _00 ),
        ALLEXCEPT ( 'Table', 'Table'[Trade1], 'Table'[Trade2] )
    )
VAR _1 =
    DIVIDE ( MAX ( 'Table'[Count] ) - _0, _0 )
RETURN
    _1

 

smpa01_0-1638194905613.png

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

This works for the given example but has a hidden assumption built in that Count is increasing every year. I think you meant to use your index column instead of Count for purposes of sorting (typically, you'd use a date dimension table for this).

@AlexisOlson  you are right. In that context, OP needs to add an index column and use the following instead

 

Measure =
VAR _00 =
    MAX ( 'Table'[Index] )
VAR _0 =
    CALCULATE (
        CALCULATE ( MAX ( 'Table'[Count] ), 'Table'[Index] < _00 ),
        ALLEXCEPT ( 'Table', 'Table'[Trade1], 'Table'[Trade2] )
    )
VAR _1 =
    DIVIDE ( MAX ( 'Table'[Count] ) - _0, _0 )
RETURN
    _1

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Lyle
Frequent Visitor

Thanks @smpa01  @AlexisOlson  I tried this, please see my sample documents.

2019 shouldn't have a % as there's no data for 2018 and the 2020 & 2021 % are not working.

 

https://contraconsolidations-my.sharepoint.com/:u:/g/personal/dylan_contracon_net/ERldVVcUILdJmn17lr...

https://contraconsolidations-my.sharepoint.com/:x:/g/personal/dylan_contracon_net/EWaLX3HYNVNOiVLzEb...

I think this might be closer to what you're after:

Growth = 
VAR CurrSum = SUM ( Box[Trips] )
VAR PrevSum =
    CALCULATE (
        SUM ( Box[Trips] ),
        DATEADD ( 'Calendar'[Date], -1, YEAR )
    )
RETURN
    IF (
        CurrSum > 0 && PrevSum > 0,
        DIVIDE ( CurrSum - PrevSum, PrevSum )
    )

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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