Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have this table (Tbl_Sales) :
SalesID | ClientID | Date | Amount
-----------------------------------------------
6 | 1 | 01/01/2021 | 100
8 | 1 | 01/01/2021 | 150
3 | 1 | 02/01/2021 | 50
1 | 1 | 09/01/2021 | 200
5 | 2 | 03/01/2021 | 100
9 | 2 | 06/01/2021 | 50
7 | 2 | 07/01/2021 | 150
3 | 2 | 07/01/2021 | 50
4 | 2 | 07/01/2021 | 200
* (Date's are in dd/mm/yyyy format)
Also, I have this table Tbl_Clients
ClientID | Limit
--------------------
1 | 220
2 | 300
The rules are that I need a measure that gets every month the last Sum of each client BUT if the sum amount of the client is over the limit I need the amount before of the sum that caused to passed the limit, Exaple's:
Client ID 1, at Jan 2021, I expecte to get 100, because first I check if the amount is over the limit, so I added the 100 (SalesID 6) then I check if next amount is over the limit, if so I dont add it to the sum.
Client ID 2, at Jan 2021, I expecte to get 200 becouse i sum the SalesID (5,9,3) = 200 and if I add SalesID 4 it will pass the limit.
Importent Notes:
1. The order of adding sum amount is by the date, and if there are more then one date, the order is by the SalesID.
2. The limit is per month, so every month the client starts from 0.
(edit:) 3. I have a date table if needed
(edit2:) 4. The sales table is with 3 milion rows, so if high Performence is possible I will be very good.
Hope It was clear enough 🙂
What you could do that should work (pending any better solution) is:
Thank you so much for trying to help I really appreciate it but unfortunately this code was not helpful, not because the result is incorrect but because of a performance with millions of lines (my file is already pretty cluttered).
After entering the code, each action I took on the file took several minutes of waiting.
When an amount will make the sum pass the limit, you want to return the latest sum without passing the limit, or you want to return the last amount instead. For example, if limit is 200 and you have 60 in 4 places, adding the 4th 60 will make it go pass the limit. So do you want to return the 3rd 60, or you want to return 180?
Return the latest sum without passing the limit (180 in your exampl)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
82 | |
70 | |
60 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |