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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Compare 2 Table and calculate

Hi,

I Have 2 Table,

Table-A

DateUser IDType
27-Dec-222211Active
27-Dec-223441Active
07-Dec-223441Active
27-Jan-232211Active
02-Jan-231154Active
02-Jan-233211Active
16-Jan-233211Active
22-Jan-235467Active
12-Feb-231233Active
21-Feb-233456Active
21-Feb-233211Active
16-Feb-231154Active

and

Table-B

DateUser IDType
27-Dec-221154Passport
27-Dec-223441Passport
07-Dec-223441Passport
27-Jan-231154Passport
02-Jan-231154Passport
02-Jan-233211Passport
16-Jan-233211Passport
22-Jan-235467Passport
12-Feb-231154Passport
21-Feb-233456Passport
21-Feb-233211Passport
16-Feb-233211Passport


Need to calculate ,

Numerator - Distinct count of User ID in Table A that matches with Prev month of User ID from Table B

Denominator - Prev month Distinct count of user ID from table B

Result need come like below,

 

DateNumeratorDenominatorRet(Num/Den)
Dec   
Jan120.5
Feb230.666666667

 

@amitchandak 

@Ashish_Mathur 

@Anonymous 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Below is my solution. And also upload my attachment for your reference.

1.Create a calendar table.

Table = CALENDAR(DATE(2022,12,1),DATE(2023,3,1))

vstephenmsft_0-1683096839342.png

2.Create the yearmonth column both in two tables.

YearMonth = FORMAT([Date],"YYYY-MMM")

vstephenmsft_1-1683096879177.png

vstephenmsft_2-1683096888305.png

3.Create measures. The first measure is to obtain the User ID in Table B for the previous month that matches the current month in Table A.

Measure = 
var _start=EOMONTH(MAX('Table-A'[Date]),-2)+1
var _end=EOMONTH(MAX('Table-A'[Date]),-1)
return
CALCULATE(MAX('Table-B'[User ID]),FILTER(ALL('Table-B'),[User ID]=MAX('Table-A'[User ID])&&[Date]>=_start&&[Date]<=_end))
Numerator = CALCULATE(DISTINCTCOUNT('Table-A'[User ID]),FILTER(ALLSELECTED('Table-A'),[YearMonth]=MAX('Table-A'[YearMonth])&&[User ID]=[Measure]))
Denominator = 
var _start=EOMONTH(MAX('Table-A'[Date]),-2)+1
var _end=EOMONTH(MAX('Table-A'[Date]),-1)
return
CALCULATE(DISTINCTCOUNT('Table-B'[User ID]),FILTER(ALL('Table-B'),[Date]>=_start&&[Date]<=_end))
Ret(Num/Den) = DIVIDE([Numerator],[Denominator])

4.Here's the result.

vstephenmsft_3-1683096969357.png

 

 

Best Regards,

Stephen Tao

 

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
Anonymous
Not applicable

Hi @Anonymous ,

 

Below is my solution. And also upload my attachment for your reference.

1.Create a calendar table.

Table = CALENDAR(DATE(2022,12,1),DATE(2023,3,1))

vstephenmsft_0-1683096839342.png

2.Create the yearmonth column both in two tables.

YearMonth = FORMAT([Date],"YYYY-MMM")

vstephenmsft_1-1683096879177.png

vstephenmsft_2-1683096888305.png

3.Create measures. The first measure is to obtain the User ID in Table B for the previous month that matches the current month in Table A.

Measure = 
var _start=EOMONTH(MAX('Table-A'[Date]),-2)+1
var _end=EOMONTH(MAX('Table-A'[Date]),-1)
return
CALCULATE(MAX('Table-B'[User ID]),FILTER(ALL('Table-B'),[User ID]=MAX('Table-A'[User ID])&&[Date]>=_start&&[Date]<=_end))
Numerator = CALCULATE(DISTINCTCOUNT('Table-A'[User ID]),FILTER(ALLSELECTED('Table-A'),[YearMonth]=MAX('Table-A'[YearMonth])&&[User ID]=[Measure]))
Denominator = 
var _start=EOMONTH(MAX('Table-A'[Date]),-2)+1
var _end=EOMONTH(MAX('Table-A'[Date]),-1)
return
CALCULATE(DISTINCTCOUNT('Table-B'[User ID]),FILTER(ALL('Table-B'),[Date]>=_start&&[Date]<=_end))
Ret(Num/Den) = DIVIDE([Numerator],[Denominator])

4.Here's the result.

vstephenmsft_3-1683096969357.png

 

 

Best Regards,

Stephen Tao

 

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

MohammadLoran25
Solution Sage
Solution Sage

Hi @Anonymous ,

1-In your Table-A Create a calculated column:

YearMOnthIndex = YEAR('Table-A'[Date])*12+MONTH('Table-A'[Date])

 

2-In your Table-B Create a similar calculated column:

YearMOnthIndex = YEAR('Table-B'[Date])*12+MONTH('Table-B'[Date])

 

3-Create a measure:

Numerator =
CALCULATE (
    DISTINCTCOUNT ( 'Table-A'[User ID] ),
    FILTER (
        CROSSJOIN ( 'TABLE-A', 'Table-B' ),
        'Table-A'[YearMOnthIndex] = 'Table-B'[YearMOnthIndex] + 1
            && 'Table-A'[User ID] = 'Table-B'[User ID]
    )
)

 

4-Create a measure: 

Denominatorr = DISTINCTCOUNT('Table-B'[User ID])

 

Then you can have their proportion as well.

 

If this answer solves your problem, give it a thumbs up and mark it as an accepted solution so the others would find what they need easier.

Regards,
Loran

 

 

Anonymous
Not applicable

Hi Loran,

 

Thanks for Replying,

This is not working. Instead showing blank value.

Can you try with the sample data which i mentioned above and share me pbix file,if possible.

 

Result needs to come like above which i mentioned.

 

Thanks,

 

@MohammadLoran25 

@Anonymous 

Yes I tried it based on your sample data and it worked.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors