Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi, I am having trouble setting up a power query such that the power query will fail if there are any rows in my first table that do not match with any rows in a second lookup table, for a left join.
To provide more context, I have a 'main table' that has Cost Center as a column, and I want to join to a lookup table for Cost Centers to pull in columns related to the Cost Center. The main table points to an Excel file that automatically gets refreshed (i.e. the file gets replaced) on a regular basis, so that my dashboard can also refresh easily. But, if there are any new Cost Centers that show up in the main table's Excel file that are not in the lookup table, I want the dashboard to throw an error so that I can manually investigate / add the required rows to the lookup table (as opposed to excluding those rows by using an inner join, for example).
BONUS: On a similar vein, I was wondering if there's a way to also throw an error if a table has a particular column with duplicate values (e.g. if the Cost Center lookup table had duplicate rows for Cost Center).
Problem 1 - If there are any new Cost Centers that show up in the main table's Excel file that are not in the lookup table, I want the dashboard to throw an error
When the correspoding values don't exist in Lookup table, all values from Lookup table will be null.
Then you can check for the existence of the null in any field of your choice (choose a field which can't be null) and mark error in the custom column.
Note, you can also check just before expanding your result by Table.IsEmpty as well.
if Table.IsEmpty([Column] then "Fail" else "Pass"
2. if there's a way to also throw an error if a table has a particular column with duplicate values
You will need to group the table and take count and do a self merge to take count in a separate column.
Create a custom column to say if count > 1, then duplicate.
Hence, in a custom column you can say
= if [Column]=null then "Fail" else "Pass"
Edit - Another approach is to use following
if List.Count(List.PositionOf(Source[Letters],[Letters],Occurrence.All))>1 then "Duplicate" else "Not Duplicate"
All these techniques I have demonstrated in following file - https://1drv.ms/x/s!Akd5y6ruJhvhuSOtm_KabLBuzL7F?e=34HFkh
Hi Vijay, how do I "mark errors" in the custom column? Tried to google but couldn't find the syntax for specifying errors.
Here are my applied steps in the query currently:
And here is my code in the Advanced Editor:
I also don't understand your "other approach" - where exactly would I be putting this line of code with the if statement?
Hi @dzzxyzz
When you do a left outer join, add a custom column to count the rows of the lookup table, if it is 0 then no row in lookup table, if it is greater than 1 then duplicated rows in lookup table
Table.RowCount([lookupTable])
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
24 | |
12 | |
12 | |
11 | |
7 |
User | Count |
---|---|
42 | |
27 | |
14 | |
13 | |
13 |