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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bml123
Post Patron
Post Patron

Check if client id exists in current year and doesn't exist in previous year

Hi,

 

I have a requirement to find if the client exists in current year but doesn't exist in previous year.

How do I achieve this?

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @bml123 

 

I simply simulated some data that would solve your problem in 2 ways.

vzhangti_0-1655879414275.png

20 and 30 are client ids that exist in this year and did not exist in the previous year.

 

Method 1:

Measure:

Measure = 
Var N1=CALCULATE(COUNT('Table'[client id]),
        FILTER(ALL('Table'),[client id]=SELECTEDVALUE('Table'[client id])&&YEAR([Date])=YEAR(TODAY())))
Var N2=CALCULATE(COUNT('Table'[client id]),
        FILTER(ALL('Table'),[client id]=SELECTEDVALUE('Table'[client id])&&YEAR([Date])=YEAR(TODAY())-1))
return
IF(N1>0&&N2=BLANK(),1,0)

vzhangti_1-1655879561893.png

 

Method 2:

Table:

Table 2 = 
Var table1=Filter(SUMMARIZE('Table','Table'[client id],'Table'[Date]),YEAR([Date])=YEAR(Today()))
Var table2=Filter(SUMMARIZE('Table','Table'[client id],'Table'[Date]),YEAR([Date])=YEAR(Today())-1)
return
Except(SUMMARIZE(table1,'Table'[client id]),SUMMARIZE(table2,'Table'[client id]))

vzhangti_2-1655879641194.png

Is there a way to output the results you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
sportive92003
Frequent Visitor

Hi, It's working well for my need (put 1 as new client if purchase after more than 1 year). But the total appears 0 ! I still looking to put it as a number to have total and do a graph with it. Have some solution for it?

v-zhangti
Community Support
Community Support

Hi, @bml123 

 

I simply simulated some data that would solve your problem in 2 ways.

vzhangti_0-1655879414275.png

20 and 30 are client ids that exist in this year and did not exist in the previous year.

 

Method 1:

Measure:

Measure = 
Var N1=CALCULATE(COUNT('Table'[client id]),
        FILTER(ALL('Table'),[client id]=SELECTEDVALUE('Table'[client id])&&YEAR([Date])=YEAR(TODAY())))
Var N2=CALCULATE(COUNT('Table'[client id]),
        FILTER(ALL('Table'),[client id]=SELECTEDVALUE('Table'[client id])&&YEAR([Date])=YEAR(TODAY())-1))
return
IF(N1>0&&N2=BLANK(),1,0)

vzhangti_1-1655879561893.png

 

Method 2:

Table:

Table 2 = 
Var table1=Filter(SUMMARIZE('Table','Table'[client id],'Table'[Date]),YEAR([Date])=YEAR(Today()))
Var table2=Filter(SUMMARIZE('Table','Table'[client id],'Table'[Date]),YEAR([Date])=YEAR(Today())-1)
return
Except(SUMMARIZE(table1,'Table'[client id]),SUMMARIZE(table2,'Table'[client id]))

vzhangti_2-1655879641194.png

Is there a way to output the results you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-zhangti 

 

Thanks for this. How do I achieve the same for any year selected rather than current year?

lbendlin
Super User
Super User

Read about the EXCEPT()  DAX function.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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