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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

LookupValue in one table based on time period

Hi everyone,

 

I am trying to find a meassure for this example. I have one table of 2 years period (2021-2022), which includes client IDs and they can repeat. I need to calculate distinctcount of client IDs, which exists in 2021, but not exist in 2022. 

LuciaZ_0-1686823163658.png

In this example it should be distinctcount of klient_id = 2 (K100001 and K100003), because these are in 2021, but not in 2022. Also, I would like to use the meassure in bigger dataset then, so the meassure should comparing always last 12 months of date and previous 12 months from it (2021 and 2022; 2020 and 2021; 2019 and 2020; etc.).

Thanks for help. 

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can try 

Lost clients =
VAR MaxYear =
    CALCULATE ( YEAR ( MAX ( 'Table'[Date] ) ), REMOVEFILTERS () )
VAR PrevYear = MaxYear - 1
VAR CurrentYearClients =
    CALCULATETABLE (
        VALUES ( 'Table'[Client ID] ),
        TREATAS ( { MaxYear }, 'Date'[Year] ),
        REMOVEFILTERS ( 'Date' )
    )
VAR PrevYearClients =
    CALCULATETABLE (
        VALUES ( 'Table'[Client ID] ),
        TREATAS ( { PrevYear }, 'Date'[Year] ),
        REMOVEFILTERS ( 'Date' )
    )
VAR NumLostClients =
    COUNTROWS ( EXCEPT ( PrevYearClients, CurrentYearClients ) )
RETURN
    NumLostClients

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Anonymous 
Do do you want to compare current year with the previous year or compare the past 12 months (from the max date available in the current filter context) to the 12 months before? Do you have adate table? 

Anonymous
Not applicable

Hi, 

I want to compare the past 12 months to the 12 months before.

johnt75
Super User
Super User

You can try 

Lost clients =
VAR MaxYear =
    CALCULATE ( YEAR ( MAX ( 'Table'[Date] ) ), REMOVEFILTERS () )
VAR PrevYear = MaxYear - 1
VAR CurrentYearClients =
    CALCULATETABLE (
        VALUES ( 'Table'[Client ID] ),
        TREATAS ( { MaxYear }, 'Date'[Year] ),
        REMOVEFILTERS ( 'Date' )
    )
VAR PrevYearClients =
    CALCULATETABLE (
        VALUES ( 'Table'[Client ID] ),
        TREATAS ( { PrevYear }, 'Date'[Year] ),
        REMOVEFILTERS ( 'Date' )
    )
VAR NumLostClients =
    COUNTROWS ( EXCEPT ( PrevYearClients, CurrentYearClients ) )
RETURN
    NumLostClients
Anonymous
Not applicable

This works, thank you 🙂

 

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.