Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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.
Solved! Go to Solution.
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:
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! 🙂
Proud to be a Super User!
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:
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:
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)
Proud to be a Super User!
Paul on Linkedin.
Hi,
Shouldn't there be a Salesperson column in Table 2 as well?
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:
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! 🙂
Proud to be a Super User!
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.
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 45 | |
| 41 | |
| 20 | |
| 17 |
| User | Count |
|---|---|
| 69 | |
| 64 | |
| 32 | |
| 31 | |
| 27 |