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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
maramice
New Member

Number of clients that bought ONLY in a specific year, or a combination of years

I have a simple dataset with CustomerID, FY, and SalesValue. If a client didn't buy anything in a certain year, there is no row. So some clients have 1 row (e.g. only 2019) and some clients have 4 rows (e.g. 2018-2022).

 

I would like to find out how many clients bought something in ONLY a certain year, for example only in 2021.

 

And then how many clients bought something only in 2021&2022, but no other years.

 

I managed to do the second bit:

20_21 =
CALCULATE (
    DISTINCTCOUNT( 'Revenue'[CustomerID] ),
    FILTER (
        VALUES ( 'Revenue'[CustomerID] ),
        CALCULATE ( DISTINCTCOUNT ( 'Revenue'[FY] ), 'Revenue'[FY] IN { 2020, 2021 } )
            = 2
    )
)
 
 
I can't figure out the first bit though (for a specific year). Preferrably, I woyuld do it with on measure only and then apply filters on a visual level, but if that's not possible creating separate measures is fine too. What I've tried but is not working is this:
FY21 =
CALCULATE (
    DISTINCTCOUNT ( 'Revenue'[CustomerID] );
    FILTER (
        Revenue;
        Revenue[FY] = "2021"
            && NOT ( Revenue[FY] ) IN { 2020; 2019; 2018 }
    )
)
 
 
Thank you
2 REPLIES 2
johnt75
Super User
Super User

If you set up a slicer to choose which financial years you want to see, you could try

# customers in FY =
VAR selectedYears =
    VALUES ( 'Revenue'[FY] )
RETURN
    SUMX (
        VALUES ( 'Revenue'[Customer ID] ),
        VAR boughtYears =
            CALCULATETABLE (
                VALUES ( 'Revenue'[FY] ),
                ALLEXCEPT ( 'Revenue', 'Revenue'[Customer ID] )
            )
        RETURN
            IF ( ISEMPTY ( EXCEPT ( boughtYears, selectedYears ) ), 1 )
    )

Thank you.

 

This does something, but the value it returns is much too low, I am not sure why.

 

What if I wanted only 2 callout values: one for customers that only bought in 2020 and one for customers that only bought in 2021? How would I create those 2 measures? Here's what I've tried but it's wrong:

20 =

CALCULATE (

    DISTINCTCOUNT( 'Revenue'[CustomerID] ),

    FILTER (

        VALUES ( 'Revenue'[CustomerID] ),

        CALCULATE ( DISTINCTCOUNT ( 'Revenue'[FY] ) ) = 2021

            && CALCULATE ( MAX ( 'Revenue'[FY] ) ) = 1

    )

)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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