Context:
I have data from monthly files that contain invoices that are not paid. (Table X)
ID | CLIENT | NAME | ... | AMOUNT |
---|---|---|---|---|
1 | A | ABC | ... | 1000 |
Each file has a united structure, so I created a custom function that processes the files and stores the data in on big table.
The complexity starts here:
ID | CLIENT | NAME | ... | AMOUNT | COMMENT | PAID |
---|---|---|---|---|---|---|
1 | A | ABC | ... | 1000 | PAID | 1 |
2 | A | ABC | ... | 1000 | PAID | 1 |
3 | B | ABC | ... | 1000 | PENDING | 0 |
I need to add the new moth's data without disturbing and/or affecting the "comments" assigned to the table in step 2 - keeping the structure and the comments in the right place.
The problem is that the new month's files contain also the previous month's unpaid invoices (PAID = 0)
I then need to remove duplicates while keeping the comments. (Table Z) (note: the paid invoices can stay there if it makes it easier) (Table Y)
ID | CLIENT | NAME | ... | AMOUNT | COMMENT | PAID |
---|---|---|---|---|---|---|
1 | A | ABC | ... | 1000 | PAID | 1 |
2 | A | ABC | ... | 1000 | PAID | 1 |
3 | B | ABC | ... | 1000 | PENDING | 0 |
...NEW DATA...(structure of the Table X )
| 3 | B | ABC | ... | 1000 | ...
I was thinking to do it all in Power Query, but I got nowhere.
A colleague suggested to do it with VBA
But so that it can be done over and over again.
Each file has a united structure, so I created a custom function that processes the files and stores the data in on big table.
Ok, I managed to create a self-referencing query. Thanks to @horseyride 's comment "See notes on self-referential powerquery tables to maintain comments upon refresh at exceleratorbi.com.au/self-referencing-tables-power-query ."
Although the problem wasn't the same. The steps were similar quite straight forward. It was quite confusing to understand the actual mechanics behind it, but the links explain it very well.
Visuals are found in the links: exceleratorbi.com.au/self-referencing-tables-power-query AND https://www.thebiccountant.com/2016/02/09/how-to-create-a-load-history-or-load-log-in-power-query-or-power-bi/?_ga=2.29192188.1106660051.1705039937-1062894945.1705039937
The only downside I found to this solution is that if you delete rows and refresh then the deleted invoices are going to appear on the bottom of the table because they are contained in TABLE X and therefore, they are appended on the bottom. But I don't see a logical reason Why would you want to do that.
Later I found out that the invoices with the same INVOICE NUMBER in each file can have varying amounts that need to be paid because the invoices can be covered in portions (sort of like Payment plans). In my data the AMOUNT is the remainder of the original invoice. This complicates things a lot. I will create another post regarding this topic.