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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.