Adding new column from merged query returns previously deleted data

razmochaev

New member
Joined
Aug 11, 2017
Messages
4
Reaction score
0
Points
0
Hi everyone.
I'm experiencing a bug, I guess. I have several queries:
1. One with payments to employess.
2. One with employees accounts, which in turn consists of three queries, from 3 different sources. I combine these 3 sources in one query, sort the by the entry date and delete the duplicates (see PQ1.png), so only fresh and unique records are stored (see PQ2.png).

But when I merge two queries (left join by Employee Name), and in query 1 I add new column with employee's account, PQ returns not the account number that is stored in query 2, but the older one that was deleted in query 2 (see PQ3.png)PQ1.PNGPQ2.PNGPQ3.PNG.
And there is one case when there is an account nubmer for employee in query 2, but an empty value is returned (not "null" as if there was no matching record, but empty, "")

Has anybody experienced anything like this?
 
Razmochaev,

If you can provide M code, I or someone else can either fix it or confirm you've found a M bug.
Just copy all the contents of the Advanced Editor.

Dan
 
The queries were made in Russian version of PQ, hope that won't be the problem.

Query 1 M Code:
let
Источник = Table.Combine({#"Выплаты через банк", #"Выплаты через кассу"}),
#"Объединенные запросы" = Table.NestedJoin(Источник,{"Физическое лицо"},#"Лицевые счета сотрудников",{"Сотрудник"},"NewColumn",JoinKind.LeftOuter),
#"Развернутый элемент NewColumn" = Table.ExpandTableColumn(#"Объединенные запросы", "NewColumn", {"Номер лицевого счета"}, {"Номер лицевого счета"}),
#"Вычисленное абсолютное значение" = Table.TransformColumns(#"Развернутый элемент NewColumn",{{"Сумма", Number.Abs, type number}}),
#"Вычисленный конец месяца" = Table.TransformColumns(#"Вычисленное абсолютное значение",{{"Период взаиморасчетов", Date.EndOfMonth, type date}}),
// Почему-то не подставляется счет Мамонтова, хотя все данные есть. Глюк, надеюсь, что исправят в обновлении.
#"Замененное значение" = Table.ReplaceValue(#"Вычисленный конец месяца","","40817810455861678029",Replacer.ReplaceValue,{"Номер лицевого счета"})
in
#"Замененное значение"

Query 2 code:
let
Источник = Table.Combine({ЗуП25_ЛицевыеСчетаСотрудников, ЗуП3_ЛицевыеСчетаСотрудников, ЛицевыеСчетаТехнические}),
#"Сортированные строки" = Table.Sort(Источник,{{"Сотрудник", Order.Ascending}, {"Месяц открытия", Order.Descending}}),
#"Добавлен пользовательский объект" = Table.AddColumn(#"Сортированные строки", "УникальныйСотрудник", each [Сотрудник]&[ИНН]),
#"Удаленные дубликаты" = Table.Distinct(#"Добавлен пользовательский объект", {"УникальныйСотрудник"}),
#"Удаленные столбцы" = Table.RemoveColumns(#"Удаленные дубликаты",{"УникальныйСотрудник"})
in
#"Удаленные столбцы"


If you need english version, I can do that.
 
Possibly it's a - more or less - known issue: try and buffer the table before selecting unique values, like:

#"Добавлен пользовательский объект" = Table.Buffer(Table.AddColumn(#"Сортированные строки", "УникальныйСотрудник", each [Сотрудник]&[ИНН])),

The issue is mentioned various times on internet, e.g. on TechNet.
 
Dear MarcelBeug,
Thank you for the solution, it worked for me!
 
Back
Top