Forum Discussion
Get the most recent transaction date
Hello to all the experts,
I have a database, that contains Warehouses inventory.
The columns are: Item ID / Warehouse name / qty. in WH / Last transaction date.
My goal is:
Get the most recent transaction date, for items that has total quantity of 0, in all WH's, in which they are contained.
In this example: items 101, 104 and 106.
(Asume that the table is sorted by Item ID and Last Trans. date)
| Item ID | WH | Qty. in WH | Date Last Trans. | Item ID | WH | Qty. in WH | Date Last Trans. | |
| 101 | A | 0 | 02/01/23 | Results: | 101 | C | 0 | 24/02/23 |
| 101 | B | 0 | 17/01/23 | 104 | B | 0 | 05/01/23 | |
| 101 | C | 0 | 24/02/23 | 106 | D | 0 | 30/03/23 | |
| 102 | A | 126 | 20/02/23 | |||||
| 103 | A | 14 | 12/03/23 | |||||
| 104 | B | 0 | 05/01/23 | |||||
| 105 | B | 0 | 15/01/23 | |||||
| 105 | C | 41 | 16/01/23 | |||||
| 106 | A | 0 | 20/03/23 | |||||
| 106 | C | 0 | 25/03/23 | |||||
| 106 | D | 0 | 30/03/23 | |||||
| 107 | A | 1 | 31/03/23 | |||||
| 107 | C | 0 | 01/04/23 | |||||
| 107 | D | 0 | 02/02/23 | |||||
| 108 | C | 18 | 03/01/23 |
Hi, Please check the below picture and the attached pbix file.
It is for creating a new table.
Expected table = VAR _expectedresulttable = CALCULATETABLE ( Data, FILTER ( VALUES ( Data[Item ID] ), CALCULATE ( ABS ( SUM ( Data[Qty. in WH] ) ) ) = 0 ) ) VAR _groupbylatestdate = GROUPBY ( _expectedresulttable, Data[Item ID], "@latestdate", MAXX ( CURRENTGROUP (), Data[Date Last Trans.] ) ) RETURN CALCULATETABLE ( Data, TREATAS ( _groupbylatestdate, Data[Item ID], Data[Date Last Trans.] ) )Thanks a lot, it did the work!
6 Replies
- CNENFRNL
Community Champion
- RafaelAri
Helper III
Thanks a lot, it did the work!
- Jihwan_Kim
Super User
Hi, Please check the below picture and the attached pbix file.
It is for creating a new table.
Expected table = VAR _expectedresulttable = CALCULATETABLE ( Data, FILTER ( VALUES ( Data[Item ID] ), CALCULATE ( ABS ( SUM ( Data[Qty. in WH] ) ) ) = 0 ) ) VAR _groupbylatestdate = GROUPBY ( _expectedresulttable, Data[Item ID], "@latestdate", MAXX ( CURRENTGROUP (), Data[Date Last Trans.] ) ) RETURN CALCULATETABLE ( Data, TREATAS ( _groupbylatestdate, Data[Item ID], Data[Date Last Trans.] ) )- RafaelAri
Helper III
Thanks a lot, it did the work!
- Ahmedx
Super User
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Get the most recent transaction date.pbix - RafaelAri
Helper III
I found some mistakes in this solution, but thanks anyway for your replay 👍