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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
nutdiablo
Frequent Visitor

Compare customer activities of 2 companies in last 2 months.

Hi All, 
Hope you are doing well.
I need to compare that is this Customer in Company B also bought with Company A before in the last 2 months.
I can check whenever that customer ever bought with Company A, but I am stuck on last 2 months.
Please help, Thank you.

Company A Table

DateCustomerRevenue
01-Jan-24CA                           1,000.00
16-Jan-24CA                           2,000.00
01-Feb-24CA                           3,000.00
16-Feb-24CA                           4,000.00
17-Mar-24CA                           5,000.00
20-Apr-24CA                           6,000.00
01-Jan-24CB                           7,000.00
01-Feb-24CB                           8,000.00
16-Jan-24CC                           9,000.00


Company B Table

DateCustomerRevenue
10-Apr-24CA                           1,000.00
27-Apr-24CB                           2,000.00
30-Apr-24CC                           3,000.00

 

Result Table

DateCustomerRevenueNo. Trasaction with Company A in last 2 monthsSum Revenue with Company A in last 2 months
10 April 2024CA                           1,000.003                                                                             12,000.00
27 April 2024CB                           2,000.001                                                                                8,000.00
30 April 2024CC                           3,000.000                                                                                             -  
1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @nutdiablo ,

Assuming there aren't any dimention tables that link Company A and Company B, the transaction count is the count of rows and the start of month begins on the first day of the month from two months before the current transaction date, try these:

Transactions within the last two months = 
VAR __END_DATE =
    SELECTEDVALUE ( TableB[Date] )
VAR __START_DATE =
    EOMONTH ( EDATE ( __END_DATE, -3 ), 0 ) + 1
RETURN
    CALCULATE (
        COUNTROWS ( TableA ),
        FILTER (
            TableA,
            TableA[Date] >= __START_DATE
                && TableA[Date] <= __END_DATE
                && TableA[Customer] = SELECTEDVALUE ( TableB[Customer] )
        )
    )
Revenue within the last two months = 
VAR __END_DATE =
    SELECTEDVALUE ( TableB[Date] )
VAR __START_DATE =
    EOMONTH ( EDATE ( __END_DATE, -3 ), 0 ) + 1
RETURN
    CALCULATE (
        SUM ( TableA[Revenue] ),
        FILTER (
            TableA,
            TableA[Date] >= __START_DATE
                && TableA[Date] <= __END_DATE
                && TableA[Customer] = SELECTEDVALUE ( TableB[Customer] )
        )
    )

danextian_0-1712052834357.png

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

2 REPLIES 2
nutdiablo
Frequent Visitor

It is working great. Thank you very much.

danextian
Super User
Super User

Hi @nutdiablo ,

Assuming there aren't any dimention tables that link Company A and Company B, the transaction count is the count of rows and the start of month begins on the first day of the month from two months before the current transaction date, try these:

Transactions within the last two months = 
VAR __END_DATE =
    SELECTEDVALUE ( TableB[Date] )
VAR __START_DATE =
    EOMONTH ( EDATE ( __END_DATE, -3 ), 0 ) + 1
RETURN
    CALCULATE (
        COUNTROWS ( TableA ),
        FILTER (
            TableA,
            TableA[Date] >= __START_DATE
                && TableA[Date] <= __END_DATE
                && TableA[Customer] = SELECTEDVALUE ( TableB[Customer] )
        )
    )
Revenue within the last two months = 
VAR __END_DATE =
    SELECTEDVALUE ( TableB[Date] )
VAR __START_DATE =
    EOMONTH ( EDATE ( __END_DATE, -3 ), 0 ) + 1
RETURN
    CALCULATE (
        SUM ( TableA[Revenue] ),
        FILTER (
            TableA,
            TableA[Date] >= __START_DATE
                && TableA[Date] <= __END_DATE
                && TableA[Customer] = SELECTEDVALUE ( TableB[Customer] )
        )
    )

danextian_0-1712052834357.png

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.