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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
TerezaPokorna
Frequent Visitor

One column - duplicates and unique values in months

Hello, I desperately need your help. I have very simple data set that contains of just two columns, date and ID where ID represents a person.

DateID
1.1.202210101
1.1.202210102
1.1.202210103
1.1.202210104
1.1.202210105
1.1.202210106
1.1.202210107
1.1.202210108
1.1.202210109
1.2.202210101
1.2.202210110
1.2.202210111
1.2.202210102
1.2.202210105
1.2.202210107

 

My goal is to figure out, how many IDs differs from the previous month. What I mean is, I know that I have 9 IDs in January, in February I have only 6 IDs. Some of them are duplicates (people that stayed in a company), hovewer some IDs left and some new IDs came. I need a measure that will count me, how many new IDs came and how many IDs left. 

 

Example: January: 9 IDs

               February: 5 IDs left, 2 new IDs came

               Net change: 6

Measure will be presented in a table for every month, I need to see how many IDs left, how many came and net change. 

 

Thank you very much for every help.

 

Tereza

1 ACCEPTED SOLUTION

@TerezaPokorna Ah, duh. Yeah, I should have figured that out, then Net Change is:

Net Change = 
    VAR __CurrentMonth = DISTINCT('Table'[ID])
    VAR __LastMonth = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[MonthSort] = MAX([MonthSort]) - 1),"ID",[ID]))
RETURN
    COUNTROWS(__LastMonth) - [Left] + [New]


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@TerezaPokorna I don't understand your 6 for net change, seems like it should be either 3 or 7. See attached PBIX below signature:

New = 
    VAR __CurrentMonth = DISTINCT('Table'[ID])
    VAR __LastMonth = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[MonthSort] = MAX([MonthSort]) - 1),"ID",[ID]))
RETURN
    COUNTROWS(EXCEPT(__LastMonth,__CurrentMonth))



Left = 
    VAR __CurrentMonth = DISTINCT('Table'[ID])
    VAR __LastMonth = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[MonthSort] = MAX([MonthSort]) - 1),"ID",[ID]))
RETURN
    COUNTROWS(EXCEPT(__CurrentMonth,__LastMonth))



Net Change = 
    VAR __CurrentMonth = DISTINCT('Table'[ID])
    VAR __LastMonth = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[MonthSort] = MAX([MonthSort]) - 1),"ID",[ID]))
RETURN
    COUNTROWS(__LastMonth) - COUNTROWS(__CurrentMonth)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thank you so much for your reply, I have tried it and it seems to work pretty well. I can explain net change of 6 = in January I have 9 IDs, 5 IDs left in February (10103, 10104, 10106, 10108, 10109), but 2 new IDs came in February (10110 and 10111). So 9-5+2. I will try it on a large data set, in my original data set I have 10 years of data by months 🙂 Thank you so much for your help.  

@TerezaPokorna Ah, duh. Yeah, I should have figured that out, then Net Change is:

Net Change = 
    VAR __CurrentMonth = DISTINCT('Table'[ID])
    VAR __LastMonth = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[MonthSort] = MAX([MonthSort]) - 1),"ID",[ID]))
RETURN
    COUNTROWS(__LastMonth) - [Left] + [New]


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Dear Greg, I wanted to ask a follow-up question if you don´t mind, you helped me with the problem above and it works nicely, however now I need to figure out if the IDs that came as new do exist in previous IDs. You created a virtual table with people who came as new, however, I need those IDs to compare to the whole history of IDs to know, if they previously existed or if they are completely new 🙂 I am not sure if I explain myself correctly 🙂

@TerezaPokorna I think something like:

Net Change = 
    VAR __CurrentMonth = DISTINCT('Table'[ID])
    VAR __Previous = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),"ID",[ID]))
RETURN
    COUNTROWS(EXCEPT(__CurrentMonth, __Previous))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
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.

May 2025 Monthly Update

Fabric Community Update - May 2025

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