Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Assign client to Rep after an event

Hello Power BI specialists,

 

I would like a little bit help with the below.

 

I have two tables. A transaction table and sales rep table. The first one includes the client name, the date of transaction and the amount. The second one includes the sales rep, the client and the date of assign. 

 

I need to find out which sales rep was assign to the client the date the client repurchase a product. Then I need to create a summary with the sales rep and the count of clients who repurchase at a spesific month. 

 

See below example. 

 

Clients Purchases  
NameDateAmount
John22/04/2019200
George06/04/2019200
Paul02/04/2019200
George31/03/2019200
Paul28/03/2019200
George25/03/2019200
Paul19/02/2019200
John05/01/2019200
George01/01/2019200

 

Sales Rep  
NameClientDate of Assign
CGeorge25/04/2019
BJohn18/04/2019
CJohn05/04/2019
BPaul01/04/2019
APaul15/03/2019
BGeorge25/02/2019
CPaul20/02/2019
AJohn06/01/2019
AGeorge02/01/2019

 

Sales RepJan-19Feb-19Mar-19Apr-19
A  1 
B  11
C    

 

George made his first repurchase on 25/03.

He has been assign to sales rep B 25/02. Therefore sales rep B takes 1 on March, for George's repurchase. 

 

John made his first repurchase on 22/04.

He has been assign to sales rep B on 18/04. Therefore sales rep B takes 1 on April, for John's repurchase. 

 

How can I calculate the above with dax?

  • Anonymous try following dax to add salesrep in purchase table and then it is easy to creat matrix to get count by sales rep

     

    SalesRep = 
     CALCULATE( 
         VALUES( Client[Name] ), 
         TOPN( 
             1, 
             FILTER( 
                 Client, 
                 Client[Client] = Purchase[Name] &&
                 Client[Date of Assign] < Purchase[Date]
            ), 
            Client[Date of Assign], 
            DESC 
        )
    )

2 Replies

  • Anonymous try following dax to add salesrep in purchase table and then it is easy to creat matrix to get count by sales rep

     

    SalesRep = 
     CALCULATE( 
         VALUES( Client[Name] ), 
         TOPN( 
             1, 
             FILTER( 
                 Client, 
                 Client[Client] = Purchase[Name] &&
                 Client[Date of Assign] < Purchase[Date]
            ), 
            Client[Date of Assign], 
            DESC 
        )
    )
  • Hi,

    Does a 1 in the third table indicate the count of clients that the Sales rep takes credit for in that month?  If yes, then 4 would indicte that there were 4 clients which that sales rep gets credit for in that month?

    Is my understanding correct?