Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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.
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.
Solved! Go to Solution.
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
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?
Hi,
I want to compare the past 12 months to the 12 months before.
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
This works, thank you 🙂
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
10 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
13 | |
12 | |
11 | |
9 |