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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.