March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
Hi, I have an issue calculating which salesperson was responsible for a client/department when an historic invoice was issued.
My tables are similar to these:
Invoices:
InvoiceID | Client | Department | InvoiceDate |
100 | 1 | A | 01.01.2023 |
101 | 1 | A | 01.02.2023 |
102 | 2 | A | 01.01.2023 |
Salespersons per Client/Department over time:
Client | Department | SalesPerson | From | To |
1 | A | JW | 01.06.2022 | 15.01.2023 |
1 | A | MS | 16.01.2023 | 01.06.2023 |
2 | A | MS | 01.01.2022 | 31.12.2023 |
Is there a way to get a calculated column in Invoices reflecting which salesperson was responsible for Client/department when invoice was issued (based on invoice date)? Meaning Invoice 100 would be assigned JW and 101 would be MS.
Or any other better approach?
Thanks a lot!
Solved! Go to Solution.
You could create a calculated column like
Salesperson =
VAR InvoiceDate = 'Invoices'[Invoice Date]
VAR Client = 'Invoices'[Client]
VAR Department = 'Invoices'[Department]
RETURN
SELECTCOLUMNS (
FILTER (
'Salespersons',
'Salespersons'[Department] = Department
&& 'Salespersons'[Client] = Client
&& 'Salespersons'[From] <= InvoiceDate
&& (
'Salespersons'[To] >= InvoiceDate
|| ISBLANK ( 'Salespersons'[To] )
)
),
"@val", 'Salespersons'[SalesPerson]
)
You could create a calculated column like
Salesperson =
VAR InvoiceDate = 'Invoices'[Invoice Date]
VAR Client = 'Invoices'[Client]
VAR Department = 'Invoices'[Department]
RETURN
SELECTCOLUMNS (
FILTER (
'Salespersons',
'Salespersons'[Department] = Department
&& 'Salespersons'[Client] = Client
&& 'Salespersons'[From] <= InvoiceDate
&& (
'Salespersons'[To] >= InvoiceDate
|| ISBLANK ( 'Salespersons'[To] )
)
),
"@val", 'Salespersons'[SalesPerson]
)
Hello,
The best way (IMO) is to join the 2 tables directly in an SQL query.
it would be something like :
A JOIN B on A.invoice_date >= b.from and a.invoice_date < b.to
< or <= depends on the original data model 🙂
Thanks for the suggestion @Thomas_Daubert , I don't have access to SQL directly, but I am sure this could have worked well too
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
129 | |
90 | |
75 | |
58 | |
53 |
User | Count |
---|---|
200 | |
104 | |
101 | |
67 | |
55 |