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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
René
Frequent Visitor

Calculate 4 years average but only when a year has a value

Hi,

 

I am currently struggeling with the following.

 

One of our PI's is that we monitor the growth of customers. Therefore we have the following condition: we call a customer a "growth customer" if he/she: grows more than 200% (ytd) then the average of the previous 4 years (only calculating with the years with turnover) and has a minimum turnover (ytd) of 12k€.

 

In Excel I have managed this, but I really love to automate this in Power BI.

 

In order to isolate the previous years, I have found the following code working:

 

Turover Year -1 = 
CALCULATE (
    [Turnover],
    FILTER (
        'Calendar',
        YEAR ( 'Calendar'[Date] )
            = YEAR ( MAX ( 'Calendar'[Date] ) ) - 1
    )
)

 

So I have 1 measure for per previous year (Year -1, -2 -3, and -4)

 

Sample data:

Customer20192020202120222023Years with TOAvg% increaseGrowth Customer
A  €    3.964 €       541 €    2.448 € 75.7413 €    2.3183268%Yes
B    €    1.918 € 19.0781 €    1.918995%Yes
C € 24.771 € 30.329 € 44.712 € 33.268 € 67.4704 € 33.270203%Yes
D € 18.940 € 16.222 € 10.231 € 15.071 € 42.1764 € 15.116279%Yes
E € 14.950 € 18.000 € 12.000 € 20.000 € 23.0004 € 16.238142%No
F   €    5.000 €    6.500 € 11.500 €                      2 €    5.750200%No (because <12k€)

 

So far, I couldn't figure out how the get this outcome (yes/no) per customer.

 

Maybe someone can help me out with this?

 

Many thanks in advance!

René

2 REPLIES 2
FreemanZ
Super User
Super User

hi @René 

try to:

1) unpivot your dataset to something like:

FreemanZ_1-1683551959411.png

about unpivot: https://learn.microsoft.com/en-us/power-query/unpivot-column

2) plot a table visual with the customer column and a measure like:

Growth Customer = 
VAR _avg =
    AVERAGEX(
        FILTER(
            data,
            data[Year]<2023
        ),
        data[Turnover]
    )
VAR _2023=
    MAXX(
        FILTER(
            data,
            data[Year]=2023
        ),
        data[Turnover]
    )
RETURN
    IF(
       _2023>_avg*2&&_2023>12,    
        "Yes", "No"
    )

it worked like:

FreemanZ_2-1683552267176.png

 

Hi @FreemanZ ,

 

Many thanks for your swift response. Seeing your answer, I realized that I didn't give you all required info. The sample data I gave was the output I'd like to achieve. The actual dataset is build up with thousands and thousands of detailed invoicelines. So I somehow first need to calculate the sum per annum.

Using your code I end up with an average per line, not per year (my bad).

 

This is how my dataset is designed:

Ren_0-1683620216382.png

 

Maybe you can help my again with this?

 

Best regards,

René

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.