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
fva6937
Frequent Visitor

Assigning Salesperson to Client based on number of orders

 

I'm trying to create a table showing who is the salesperson with more affinity with the client.

For that:

- Whoever had more orders from the client is "assigned" to the client.

- In case of a tie, the salesperson who did the last order is.  

 

Screen Shot 2018-01-27 at 21.20.46.png

Help 🙂 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@fva6937

 

Please try this MEASURE

 

Desired SalesPerson =
VAR myTable1 =
    TOPN (
        1,
        SUMMARIZE (
            SalesTable,
            SalesTable[Salesperson_ID],
            "Count", COUNT ( SalesTable[Salesperson_ID] )
        ),
        [Count], DESC
    )
VAR myTable2 =
    TOPN (
        1,
        SUMMARIZE ( SalesTable, SalesTable[Salesperson_ID], SalesTable[Date] ),
        SalesTable[Date], DESC
    )
VAR MostOrders =
    CALCULATE ( LASTNONBLANK ( SalesTable[Salesperson_ID], 1 ), mytable1 )
VAR LastOrder =
    CALCULATE ( LASTNONBLANK ( SalesTable[Salesperson_ID], 1 ), mytable2 )
RETURN
    IF ( COUNTROWS ( mytable1 ) = 1, MostOrders, LastOrder )

Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@fva6937

 

Please try this MEASURE

 

Desired SalesPerson =
VAR myTable1 =
    TOPN (
        1,
        SUMMARIZE (
            SalesTable,
            SalesTable[Salesperson_ID],
            "Count", COUNT ( SalesTable[Salesperson_ID] )
        ),
        [Count], DESC
    )
VAR myTable2 =
    TOPN (
        1,
        SUMMARIZE ( SalesTable, SalesTable[Salesperson_ID], SalesTable[Date] ),
        SalesTable[Date], DESC
    )
VAR MostOrders =
    CALCULATE ( LASTNONBLANK ( SalesTable[Salesperson_ID], 1 ), mytable1 )
VAR LastOrder =
    CALCULATE ( LASTNONBLANK ( SalesTable[Salesperson_ID], 1 ), mytable2 )
RETURN
    IF ( COUNTROWS ( mytable1 ) = 1, MostOrders, LastOrder )

Regards
Zubair

Please try my custom visuals

Thanks!!!

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.