Keep duplicate values in Power Query to run Pivot Table

%3CLINGO-SUB%20id%3D%22lingo-sub-1426940%22%20slang%3D%22en-US%22%3EKeep%20duplicate%20values%20in%20Power%20Query%20to%20run%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1426940%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20last%20month%20I%20have%20run%20an%20automated%20report%20to%20keep%20track%20on%20some%20performance%20analysis.%3C%2FP%3E%3CP%3EI'm%20using%20Power%20Query%20in%20order%20to%20to%20get%20data%20automatically%20from%20two%20different%20sources.%20The%20two%20queries%20are%3A%3C%2FP%3E%3CP%3E-%20A%3A%20it%20includes%20the%20name%20of%20the%20product%2C%20the%20SKU%20of%20the%20product%2C%20the%20category%20code%20and%20the%20sale%20date%3C%2FP%3E%3CP%3E-%20B%3A%20it%20includes%20the%20name%20of%20the%20product%2C%20the%20SKU%20of%20the%20product%2C%20the%20category%20code%2C%20the%20sale%20date%2C%20the%20quantity%20sold%20and%20the%20revenue%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThrough%20Power%20Pivot%20I%20then%20organize%20my%20data%20into%20a%20pivot%20table%20that%20-%20by%20filtering%20by%20date%20or%20category%20-%20gives%20me%20the%20all%20the%20info%20I%20need.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20problem%20I%20need%20help%20for%20occurs%20when%20a%20line%20appears%20more%20than%20one%20time%20in%20my%20A%20query%20(all%20the%20values%20are%20the%20same%20despite%20the%20date).%20In%20fact%2C%20in%20these%20cases%2C%20when%20I%20try%20to%20update%20my%20query%20and%20run%20my%20pivot%20table%2C%20the%20error%20message%20%22the%20column%20contains%20a%20duplicate%20value%20and%20this%20is%20not%20allowed%20for%20columns%20on%20the%20one%20side%20of%20many%20to%20one%20relationship%20or%20for%20columns%20that%20are%20used%20as%20the%20primary%20key%20of%20a%20table%22%20pops%20up.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20to%20sum%20up%2C%20at%20the%20end%2C%20I%20would%20like%20to%20have%20multiple%20lines%20with%20the%20same%20value%20in%20pivot%2C%20in%20case%20a%20specific%20products%20has%20been%20sold%20in%20different%20days.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20all%20in%20advance!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%2C%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ELorenzo%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1426940%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1427002%22%20slang%3D%22en-US%22%3ERe%3A%20Keep%20duplicate%20values%20in%20Power%20Query%20to%20run%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1427002%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F683621%22%20target%3D%22_blank%22%3E%40LorenzoMolteni%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELorenzo%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIt's%20not%20clear%20what%20is%20the%20relationship%20between%20tables%20A%20and%20B.%20In%20table%20A%20you%20have%20products%20attributes%20(SKU%2C%20name%2C%20category)%2C%20it's%20not%20clear%20why%20do%20you%20keep%20the%20date%20here.%3C%2FP%3E%0A%3CP%3EIn%20table%20B%20there%20are%20product%20SKU%2C%20date%20of%20sale%2C%20qty%20and%20cost.%20Why%20do%20you%20repeat%20category%2C%20name%20and%20code%20here%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20remove%20extra%20data%20you%20may%20build%20one%20to%20many%20relationship%20between%20A%20and%20B%20(%20so%20called%20dim%20table%20and%20fact%20table).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20addition%20you%20need%20one%20more%20table%2C%20Calendar%2C%20which%20could%20be%20built%20automatically%20within%20Power%20Pivot%2C%20but%20better%20to%20generate%20by%20another%20query.%20It%20will%20be%20one%20to%20many%20with%20table%20B.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20that%20model%20it%20shall%20be%20no%20conflicts%20with%20reporting%20PivotTables.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1439932%22%20slang%3D%22en-US%22%3ERe%3A%20Keep%20duplicate%20values%20in%20Power%20Query%20to%20run%20Pivot%20Table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1439932%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Sergei%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20reply.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20agree%20on%20removing%20unnecessary%20data%20from%20table%20B.%20Regarding%20to%20the%20date%20included%20in%20table%20A%2C%20I%20was%20not%20clear%20on%20that.%20So%20basically%2C%20on%20table%20A%20I%20have%20the%20go%20live%20date%20of%20a%20specific%20product%20and%20on%20table%20B%20the%20selling%20date%20of%20that%20same%20product%20(at%20the%20end%20of%20my%20analysis%20it%20would%20be%20ideal%20to%20only%20show%20sales%20coming%20from%20the%20same%20day%20the%20product%20was%20put%20online%2C%20but%20that%20can%20be%20done%20filtering%20in%20excel%20as%20well).%20The%20problem%20is%20another%20one%3A%20in%20fact%2C%20since%20sometimes%20a%20product%20may%20be%20put%20online%20on%20day%201%2C%20for%20example%2C%20and%20then%20again%20on%20day%2015%2C%20my%20query%20is%20only%20able%20to%20process%20if%20removing%20duplicate%20SKUs.%20Because%20of%20this%20I'm%20not%20able%20to%20run%20performances%20analysis%20both%20for%20day%201%20and%2015%20but%20only%20for%20day%201%20because%20%22the%20table%20contains%20a%20duplicate%20value%20and%20this%20is%20not%20allowed%20for%20columns%20on%20the%20one%20side%20of%20a%20many-to-one%20relationship%20or%20for%20columns%20that%20are%20used%20as%20the%20primary%20key%20of%20a%20table%22%20and%20so%20I%20have%20to%20exclude%20the%20duplicate%20SKUs%20from%20the%20second%20go%20live%20date.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20please%20advise%20on%20how%20can%20I%20manage%20this%20relationship%20on%20power%20query%20in%20order%20to%20solve%20this%20problem%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20in%20advance!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%2C%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ELorenzo%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi all,

 

In the last month I have run an automated report to keep track on some performance analysis.

I'm using Power Query in order to to get data automatically from two different sources. The two queries are:

- A: it includes the name of the product, the SKU of the product, the category code and the sale date

- B: it includes the name of the product, the SKU of the product, the category code, the sale date, the quantity sold and the revenue

 

Through Power Pivot I then organize my data into a pivot table that - by filtering by date or category - gives me the all the info I need.

 

The problem I need help for occurs when a line appears more than one time in my A query (all the values are the same despite the date). In fact, in these cases, when I try to update my query and run my pivot table, the error message "the column contains a duplicate value and this is not allowed for columns on the one side of many to one relationship or for columns that are used as the primary key of a table" pops up.

 

Just to sum up, at the end, I would like to have multiple lines with the same value in pivot, in case a specific products has been sold in different days.

 

Thank you all in advance!

 

Best,


Lorenzo

 

 

 

2 Replies
Highlighted

@LorenzoMolteni 

Lorenzo,

 

It's not clear what is the relationship between tables A and B. In table A you have products attributes (SKU, name, category), it's not clear why do you keep the date here.

In table B there are product SKU, date of sale, qty and cost. Why do you repeat category, name and code here?

 

If remove extra data you may build one to many relationship between A and B ( so called dim table and fact table).

 

In addition you need one more table, Calendar, which could be built automatically within Power Pivot, but better to generate by another query. It will be one to many with table B.

 

With that model it shall be no conflicts with reporting PivotTables.

Highlighted

@Sergei Baklan 

Hi Sergei,

 

Thanks for your reply.

 

I agree on removing unnecessary data from table B. Regarding to the date included in table A, I was not clear on that. So basically, on table A I have the go live date of a specific product and on table B the selling date of that same product (at the end of my analysis it would be ideal to only show sales coming from the same day the product was put online, but that can be done filtering in excel as well). The problem is another one: in fact, since sometimes a product may be put online on day 1, for example, and then again on day 15, my query is only able to process if removing duplicate SKUs. Because of this I'm not able to run performances analysis both for day 1 and 15 but only for day 1 because "the table contains a duplicate value and this is not allowed for columns on the one side of a many-to-one relationship or for columns that are used as the primary key of a table" and so I have to exclude the duplicate SKUs from the second go live date. 

 

Can you please advise on how can I manage this relationship on power query in order to solve this problem?

 

Thank you in advance!

 

Best,


Lorenzo