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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
wenners68
Helper II
Helper II

Renewal Sales by Salesperson

Hi,

I have 3 tables, 2020 sales, 2019 sales and a Salesperson table.

There's a relationship between 2020 sales and Salesperson.

 

I need to total what the salesperson sold in 2020 and then total what the clients he sold to in 2020 had bought in 2019 and show the difference. I can't link the salesperson to 2019 because of some of the salespeople in 2020 didn't work at the company in 2019. This would be easy to do in SQL, but with DAX I'm not sure.

 

Capture.PNG

 

1 ACCEPTED SOLUTION
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @wenners68 ,

 

This can be accomplished by the following calculated table:

Table = 
ADDCOLUMNS(VALUES('2020Sales'[Salesperson]), 
    "Total",
    VAR _curSP = [Salesperson]
    VAR _salesTableForcurSP = SUMMARIZE(FILTER('2020Sales', '2020Sales'[Salesperson] = _curSP), [Client], "curTotal", SUM('2020Sales'[Total]), "sales2019", 
        VAR _curClient = [Client]
        RETURN SUMX(FILTER(Sales2019, Sales2019[Client] = _curClient), [Total]))
    RETURN
    SUMX(_salesTableForcurSP, [curTotal]-[sales2019])
)

Result:

image.png

PBIX can be found here.

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

 





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
PaulDBrown
Community Champion
Community Champion

@wenners68 

As Marcus suggests, I would go about this by merging the tables.

 

However, if you set up your model correctly, it is pretty simple to do:

Model.JPG

 

And then by creating measures for the simple sum of sales for each year and the direct difference between the two:

 

 

Sales 2019 = SUM(Sales2019[Sales])

Sales 2020 = SUM(Sales2020[Sales])

Dif Sales = [Sales 2020]-[Sales 2019]

 

And setting up the matrix using the Salesperson and Client from their respective lookup/Dim tables, you get:

Result.JPG

 

I believe this works because the leading filter is Saleperson from the Saleperson lookup table. This filters the Clients in the Sales 2020 table. Now, since the clients are unique in the Sales 2020 table, and there is a bi-directional one-to-one relationship with the Client lookup table, the filtering done by the Salespeson propagates through to the Client Lookup table which then in turn filters the Sales 2019 table. Does that make sense? (you could probably even leave out the Client lookup table altogether and establish a one-to-one relationship between both sales tables by linking the Client fields)

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Ashish_Mathur
Super User
Super User

Hi,

Shouldn't there be a Salesperson column in Table 2 as well?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi @wenners68 ,

 

This can be accomplished by the following calculated table:

Table = 
ADDCOLUMNS(VALUES('2020Sales'[Salesperson]), 
    "Total",
    VAR _curSP = [Salesperson]
    VAR _salesTableForcurSP = SUMMARIZE(FILTER('2020Sales', '2020Sales'[Salesperson] = _curSP), [Client], "curTotal", SUM('2020Sales'[Total]), "sales2019", 
        VAR _curClient = [Client]
        RETURN SUMX(FILTER(Sales2019, Sales2019[Client] = _curClient), [Total]))
    RETURN
    SUMX(_salesTableForcurSP, [curTotal]-[sales2019])
)

Result:

image.png

PBIX can be found here.

 

Kind regards

Djerro123

-------------------------------

If this answered your question, please mark it as the Solution. This also helps others to find what they are looking for.

Keep those thumbs up coming! 🙂

 





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

Proud to be a Super User!




mwegener
Most Valuable Professional
Most Valuable Professional

Hi @wenners68 ,

 

why do you want to do it with DAX?

I would recommend a merge with Power Query.

 

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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