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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Didik62
Frequent Visitor

how to calculate ternd over last year with monthly average measure

Hi.

I need help to create the logic to get value of trend over last year.

I have create monthly average (current year) and monthly average (last year) and able to get trend % , but once i slice on area ID or Product ID, some error of visual happen.

my expectation is to know in area ID FD1 what productID that decrease/increase (also in reverse way)

 

Here my data

 

Month IDArea IDProduct IDSales
202301FD1A34
202302FD1A12
202303FD1A44
202304FD1A76
202305FD1A123
202306FD1A32
202307FD1A87
202308FD1A39
202309FD1A33
202310FD1A12
202311FD1A55
202312FD1A88
202401FD1A23
202402FD1A23
202403FD1A45
202404FD1A87
202405FD1A12
202406FD1A17
202407FD1A34
202408FD1A98
202409FD1A62
202410FD1A60
202411FD1A22
202412FD1A67
202301FD1B11
202303FD1B34
202304FD1B12
202305FD1B75
202306FD1B87
202308FD1B1
202309FD1B23
202310FD1B65
202311FD1B55
202401FD1B64
202402FD1B12
202403FD1B73
202404FD1B19
202406FD1B98
202407FD1B12
202408FD1B56
202409FD1B32
202411FD1B44
202412FD1B18
202302FD1C5
202307FD1C43
202312FD1C43
202405FD1C23
202410FD1C77
202404FD1C19
202406FD1C98
202407FD1C12
202408FD1C56
202301FD2A12
202302FD2A17
202303FD2A34
202304FD2A98
202305FD2A62
202306FD2A60
202307FD2A22
202308FD2A67
202309FD2A33
202310FD2A12
202311FD2A55
202312FD2A88
202401FD2A23
202402FD2A23
202403FD2A45
202404FD2A87
202405FD2A12
202406FD2A17
202407FD2A34
202408FD2A98
202409FD2A62
202410FD2A60
202411FD2A22
202412FD2A67
202301FD2B11
202303FD2B34
202304FD2B12
202305FD2B75
202306FD2B87
202308FD2B1
202309FD2B23
202310FD2B65
202311FD2B55
202401FD2B64
202402FD2B34
202403FD2B12
202404FD2B12
202406FD2B55
202407FD2B88
202408FD2B23
202409FD2B23
202411FD2B45
202412FD2B87
202302FD2C12
202307FD2C17
202312FD2C34
202405FD2C98
202410FD2C23
202404FD2C19
202406FD2C98
202407FD2C12
202408FD2C56

 

and these are my expectation result

Expected Visual   
Dinamically within visual 1,2 and 3  
     
     
Visual 1YearMonthly AvgTrend over last Year 
a2023172.9  
b2024213.5
23.5%
(b-a)/a
     
     
Visual 2Area IDTrend over last Year  
 FD116.0%  
 FD231.7%  
     
     
Visual 3Product IDTrend over last Year  
 A-7.9%  
 B8.0%  
 C91.9%  

 

 

Hopefully i can get your suggested solution

 

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Didik62 ,

I created a sample pbix file(see the attachment), please check if that is what you want to.

Monthly Avg = DIVIDE(SUM('Table'[Sales]),12)
Trend over last Year = 
VAR _curyear =
    SELECTEDVALUE ( 'Table'[Year] )
VAR _preyear =
    CALCULATE (
        MAX ( 'Table'[Year] ),
        FILTER ( ALLSELECTED ( 'Table'[Year] ), 'Table'[Year] < _curyear )
    )
VAR _cursales = [Monthly Avg]
VAR _pysales =
    CALCULATE (
       [Monthly Avg],
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] = _preyear )
    )
RETURN
    DIVIDE ( _cursales - _pysales, _pysales )
AID Trend over last Year = 
VAR _maxyear =
    CALCULATE ( MAX ( 'Table'[Year] ), ALLSELECTED ( 'Table'[Year] ) )
VAR _lastyear = _maxyear - 1
VAR _aid =
    SELECTEDVALUE ( 'Table'[Area ID] )
VAR _cursales =
    CALCULATE ( [Monthly Avg], FILTER ( 'Table', 'Table'[Year] = _maxyear ) )
VAR _pysales =
    CALCULATE (
       [Monthly Avg],
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Area ID] = _aid
                && 'Table'[Year] = _lastyear
        )
    )
RETURN
     DIVIDE ( _cursales - _pysales, _pysales )
PID Trend over last Year = 
VAR _maxyear =
    CALCULATE ( MAX ( 'Table'[Year] ), ALLSELECTED ( 'Table'[Year] ) )
VAR _lastyear = _maxyear - 1
VAR _pid =
    SELECTEDVALUE ( 'Table'[Product ID] )
VAR _cursales =
    CALCULATE ( [Monthly Avg], FILTER ( 'Table', 'Table'[Year] = _maxyear ) )
VAR _pysales =
    CALCULATE (
        [Monthly Avg],
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Product ID] = _pid
                && 'Table'[Year] = _lastyear
        )
    )
RETURN
    DIVIDE ( _cursales - _pysales, _pysales )

vyiruanmsft_0-1739944084287.png

Best Regards

View solution in original post

8 REPLIES 8
ryan_mayu
Super User
Super User

what's the calculation logic of visual 2 and visual 3?





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

Proud to be a Super User!




I am sorry.

since the visual 1 can be multi year (range 5 years), i need to grasp the average of trend value for visual 2 and 3

actually, i would like to create value to determine which AREA ID and Product ID that have negative or positive trend comparing monthly average in each year of data.

 

Thank you

@Didik62 

pls see the attachment below





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

Proud to be a Super User!




Thank you for your help to re-create it on PBIX.

after checking, i found the [measure4] calculation seems not correct when i slice it by area ID FD1 and Product ID A meanwhile the value of [measure] is correct

 

FD1 2023 90.75

FD1 2024 105.25

 

A 2023 52.92

A 2024 45.83

[Measure4] should be -13.39%

 

it happen also to [measure2]

 

my next question is if i have more Product ID column, should i create measure for each ID collumn?

 

Thank you once again

Anonymous
Not applicable

Hi @Didik62 ,

I created a sample pbix file(see the attachment), please check if that is what you want to.

Monthly Avg = DIVIDE(SUM('Table'[Sales]),12)
Trend over last Year = 
VAR _curyear =
    SELECTEDVALUE ( 'Table'[Year] )
VAR _preyear =
    CALCULATE (
        MAX ( 'Table'[Year] ),
        FILTER ( ALLSELECTED ( 'Table'[Year] ), 'Table'[Year] < _curyear )
    )
VAR _cursales = [Monthly Avg]
VAR _pysales =
    CALCULATE (
       [Monthly Avg],
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Year] = _preyear )
    )
RETURN
    DIVIDE ( _cursales - _pysales, _pysales )
AID Trend over last Year = 
VAR _maxyear =
    CALCULATE ( MAX ( 'Table'[Year] ), ALLSELECTED ( 'Table'[Year] ) )
VAR _lastyear = _maxyear - 1
VAR _aid =
    SELECTEDVALUE ( 'Table'[Area ID] )
VAR _cursales =
    CALCULATE ( [Monthly Avg], FILTER ( 'Table', 'Table'[Year] = _maxyear ) )
VAR _pysales =
    CALCULATE (
       [Monthly Avg],
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Area ID] = _aid
                && 'Table'[Year] = _lastyear
        )
    )
RETURN
     DIVIDE ( _cursales - _pysales, _pysales )
PID Trend over last Year = 
VAR _maxyear =
    CALCULATE ( MAX ( 'Table'[Year] ), ALLSELECTED ( 'Table'[Year] ) )
VAR _lastyear = _maxyear - 1
VAR _pid =
    SELECTEDVALUE ( 'Table'[Product ID] )
VAR _cursales =
    CALCULATE ( [Monthly Avg], FILTER ( 'Table', 'Table'[Year] = _maxyear ) )
VAR _pysales =
    CALCULATE (
        [Monthly Avg],
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Product ID] = _pid
                && 'Table'[Year] = _lastyear
        )
    )
RETURN
    DIVIDE ( _cursales - _pysales, _pysales )

vyiruanmsft_0-1739944084287.png

Best Regards

Thank you for your help. it is perfectly solve my need.

but one thing that i wonder to add is average of each measure (trend over year, AID trend and PID trend) since the data is should be cover not only last 2 year but for 5 year.

For the average, i would like to calculate avarage of trend 2024 to 2023, 2023 to 2022, 2022 to 2021.

 

i have tried to create measure using

CALCULATE(AVERAGEX(SUMMARIZE('Table','Table'[YEAR],'Table'[Area ID],"A",[AID trend over last year]),[A]))
 
but it run so slow due to the data volume is so large.
any advice how to add this calculation inside or outside the measure?
 
Thank you

@Didik62 

you can try this

 

Measure 4 =
var _last=sumx(FILTER(all('Table'),'Table'[Year]=max('Table'[Year])-1&&'Table'[Area ID]=max('Table'[Area ID])&&'Table'[Product ID]=max('Table'[Product ID])),'Table'[Sales])/CALCULATE(DISTINCTCOUNT('Table'[Month ID]),FILTER(all('Table'),'Table'[Product ID]=max('Table'[Product ID])&&'Table'[Area ID]=max('Table'[Area ID])&&'Table'[Year]=max('Table'[Year])-1))
return if(max('Table'[Year])=CALCULATE(min('Table'[Year]),all('Table')),blank(),([Measure]-_last)/_last)
 
you can only display either area +product or product. becuase they can't simply use average function to get the result.

 





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

Proud to be a Super User!




for visual 2 and 3, using the same logic with visual 1 (for value trend over last year) and sliced with Area ID (visual 2) and with Product ID (visual 3)

i would like to create table visual on the dashboard

 

Thank you

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.