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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

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 )

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 )

Thanks!!!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.