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
Jocky
Frequent Visitor

Determine if a value was present in previous month

Hi there,

 

I have data that is structured somewhat as follows:

Employee numberMonth
1112022 01
2222022 01
3332022 01
4442022 01
5552022 01
6662022 01
7772022 01
8882022 01
9992022 01
1112022 02
2332022 02
3332022 02
4442022 02
4552022 02
5552022 02
6662022 02
7772022 02
8882022 02
1112022 03
2332022 03
3332022 03
4442022 03
4552022 03
5552022 03
7772022 03
8882022 03
8992022 03

 

As you can see, the data is a continuous set of employee numbers for multiple periods of time (Jan to March 2022).  In January, all employees are present but as the months go on, so new ones are added (eg 233, 455 and 899) and some are deleted (eg 222, 999 and 666).

 

I am looking for a solution that will determine what values are in a current month that are already there in the previous month.  So for example, 111 is there in Jan, Feb and Mar, therefore it is a yes for Feb and Mar.  Whereas 233 is only there in Feb and Mar, so it is a yes for Mar but no for Feb (as it wasn't there in January.

 

Example of output.

 

Employee numberMonthThere previous month?
1112022 01 
2222022 01 
3332022 01 
4442022 01 
5552022 01 
6662022 01 
7772022 01 
8882022 01 
9992022 01 
1112022 02Y
2332022 02N
3332022 02Y
4442022 02Y
4552022 02N
5552022 02Y
6662022 02Y
7772022 02Y
8882022 02Y
1112022 03Y
2332022 03Y
3332022 03Y
4442022 03Y
4552022 03Y
5552022 03Y
7772022 03Y
8882022 03Y
8992022 03N

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Jocky , Try like

 

New column
var _cnt = countx(filter(Table, [Employee Number] = earlier([Employee number) && [Month] < earlier([Month])), [Employee Number])
return
if(isblank(_cnt), "N", "Y")

 

for Measure approch refer

Customer Retention Part 1:
https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-1-Month-on-Month-Retention/b...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Flag =
NOT ISEMPTY(
    FILTER(
        HR,
        HR[Employee number] = EARLIER( HR[Employee number] )
            && HR[Month] < EARLIER( HR[Month] )
    )
)

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@Jocky , Try like

 

New column
var _cnt = countx(filter(Table, [Employee Number] = earlier([Employee number) && [Month] < earlier([Month])), [Employee Number])
return
if(isblank(_cnt), "N", "Y")

 

for Measure approch refer

Customer Retention Part 1:
https://community.powerbi.com/t5/Community-Blog/Customer-Retention-Part-1-Month-on-Month-Retention/b...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.