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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.