PowerPivot-Create (from existing table) unique ID table/formula (multi columns) for m2m relationship

%3CLINGO-SUB%20id%3D%22lingo-sub-2145867%22%20slang%3D%22en-US%22%3EPowerPivot-Create%20(from%20existing%20table)%20unique%20ID%20table%2Fformula%20(multi%20columns)%20for%20m2m%20relationship%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2145867%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EI%26nbsp%3Bwould%20please%20like%20some%20advice%20or%20other%20suggestions%20as%20to%20what%20would%20be%20the%20best%20solution%20for%20this%20problem.%20I've%20posted%20in%20StackOverflow%20as%20well%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fstackoverflow.com%2Fquestions%2F66243432%2Fpower-pivot-create-from-existing-table-unique-id-table-formula-with-multiple%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fstackoverflow.com%2Fquestions%2F66243432%2Fpower-pivot-create-from-existing-table-unique-id-table-formula-with-multiple%26nbsp%3B%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%202%20different%20data%20files%20that%20Power%20Query%20pulls%20in%20and%20transforms%20(One%20stock%20file%2C%20other%20one%20Sales).%20These%20are%20both%20loaded%20into%20the%20Data%20model%20and%20measures%20added%2C%20and%20then%20used%20in%20various%20Pivot%20Table%20Reports.%20Both%20these%20Data%20tables%20have%20100%20000's%20of%20rows%20and%20between%2030%20and%2050%20columns.%3C%2FP%3E%3CP%3EOne%20of%20the%20Pivot%20Table%20reports%20I%20need%20to%20combine%20these%20to%20Data%20files%20to%20show%20stock%20and%20Sales.%20This%20cannot%20currently%20happen%20because%20it's%20a%20many%20to%20many%20relationship.%20I'm%20adding%20all%20the%20Pivot%20Table%20columns%20(Site%2C%20Article%2C%20Barcode%2C%20StockQty%2C%20etc)%20from%20the%20Stock%20file%20and%20just%20want%20to%20add%20the%20Sales%20Value%20and%20Units%20from%20the%20Sales%20File.%20Columns%20that%20need%20to%20match%20between%20the%20Stock%20and%20Sales%20data%20are%3CSPAN%3E%26nbsp%3B%3CEM%3ESite%3CSPAN%3E%26nbsp%3Band%3CSPAN%3E%26nbsp%3B%3CEM%3EBarcode.%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EI've%20tried%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CUL%3E%3CLI%3EJust%20adding%20the%20sum%20measure%20from%20the%20sales%20file%20to%20my%20Pivot%20Table%20report%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3ETotal%20Sales%3A%3DCALCULATE(SUM(DailySalesRaw%5BSalesValue%5D)%2CDailySalesRaw%5BSalesQuantity%5D%26gt%3B0)%3C%2FFONT%3E%3C%2FP%3E%3CP%3EBut%20then%20all%20the%20values%20are%20the%20same%20because%20of%20the%20many%20to%20many%20relationship.%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22VzWOS.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F255748iFF826BFAA13DB5E9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22VzWOS.png%22%20alt%3D%22VzWOS.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3EAdding%20a%20measure%20to%20my%20Stock%20file%20(Unit_Packsize%20table%20are%20'Master%20tables'%20with%20distinct%3CSPAN%3E%3CSPAN%3E%26nbsp%3B%3CEM%3EBarcodes%2C%20but%20they%20do%20not%20include%20all%20the%3CSPAN%3E%26nbsp%3B%3CEM%3EBarcodes%3CSPAN%3E%26nbsp%3Bfound%20on%20the%20data%20files).%20This%20seem%20to%20correctly%20add%20the%20values%2C%20but%20I%20want%20to%20avoid%20using%20this%20table%20since%20it's%20not%20always%20up%20to%20date%20and%20will%20exclude%20items%20not%20found%20(Pack%20size%3DN%2FA)%2C%20thus%20not%20all%20values%20will%20be%20added.%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%3CFONT%20color%3D%22%23FF0000%22%3ESales%20Total%3A%3DCALCULATE(SUM(DailySalesRaw%5BSalesValue%5D)%2CDailyStockData%2CUnitSize_PackSize)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22966tF.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F255751i48890E1E048CF3F2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22966tF.png%22%20alt%3D%22966tF.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3ETried%20aggregating%20the%202%20data%20files%20in%20Power%20Query%20to%20create%20a%20single%20table%20that%20has%202%20columns%20with%20unique%20ID's(%3CEM%3E%3CEM%3ESite%3CSPAN%3E%26nbsp%3Band%3CSPAN%3E%26nbsp%3B%3CEM%3EBarcode).%20I%20can%20then%20create%20one%20to%20many%20relationships%2C%20which%20should%20solve%20the%20problem.%20I%20believe%20there%20should%20be%20an%20easier%20way....%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FEM%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLI%3E%3C%2FUL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EQuestion%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EWhat%20is%20the%20best%20way%20to%20do%20this%3A%3C%2FP%3E%3COL%3E%3CLI%3EUse%20Power%20Query%20to%20create%20a%20lookup%20ID%20table%20from%20the%20Sales%20data%3F%20(This%20report%20is%20run%20every%20week%2C%20so%20constantly%20uses%20new%20data%20files)%3C%2FLI%3E%3CLI%3EIs%20there%20a%20formula%20in%20Power%20Pivot%20Data%20Model%20that%20can%20sum%20the%20total%20value%20when%20the%3CSPAN%3E%26nbsp%3B%3CEM%3ESite%3CSPAN%3E%26nbsp%3Band%3CSPAN%3E%26nbsp%3B%3CEM%3EBarcode%3CSPAN%3E%26nbsp%3Bmatch%3F%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FLI%3E%3CLI%3EHow%20to%20create%20a%20lookup%20ID%20table%20that%20only%20includes%20distinct%3CSPAN%3E%3CSPAN%3E%26nbsp%3B%3CEM%3ESite%3CSPAN%3E%26nbsp%3Band%3CSPAN%3E%26nbsp%3B%3CEM%3EBarcode%3CSPAN%3E%26nbsp%3Bfrom%20the%20Sales%20table%20in%20Power%20Pivot%20Model%3F%20(Without%20manually%20creating%20a%20table%20as%20mentioned%20above.%20I've%20only%20managed%20to%20use%20distinct%20with%201%20column)%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLI%3E%3C%2FOL%3E%3CP%3EImage%20of%20Data%20Model%20layout%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22VtS42.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F255752i5290DAFA5279CBBE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22VtS42.png%22%20alt%3D%22VtS42.png%22%20%2F%3E%3C%2FSPAN%3E%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-2145867%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

I would please like some advice or other suggestions as to what would be the best solution for this problem. I've posted in StackOverflow as well: https://stackoverflow.com/questions/66243432/power-pivot-create-from-existing-table-unique-id-table-...

 

I have 2 different data files that Power Query pulls in and transforms (One stock file, other one Sales). These are both loaded into the Data model and measures added, and then used in various Pivot Table Reports. Both these Data tables have 100 000's of rows and between 30 and 50 columns.

One of the Pivot Table reports I need to combine these to Data files to show stock and Sales. This cannot currently happen because it's a many to many relationship. I'm adding all the Pivot Table columns (Site, Article, Barcode, StockQty, etc) from the Stock file and just want to add the Sales Value and Units from the Sales File. Columns that need to match between the Stock and Sales data are Site and Barcode.

 

I've tried:

  • Just adding the sum measure from the sales file to my Pivot Table report

Total Sales:=CALCULATE(SUM(DailySalesRaw[SalesValue]),DailySalesRaw[SalesQuantity]>0)

But then all the values are the same because of the many to many relationship.

VzWOS.png

 

  • Adding a measure to my Stock file (Unit_Packsize table are 'Master tables' with distinct Barcodes, but they do not include all the Barcodes found on the data files). This seem to correctly add the values, but I want to avoid using this table since it's not always up to date and will exclude items not found (Pack size=N/A), thus not all values will be added.

Sales Total:=CALCULATE(SUM(DailySalesRaw[SalesValue]),DailyStockData,UnitSize_PackSize)

 

966tF.png

 

 

  • Tried aggregating the 2 data files in Power Query to create a single table that has 2 columns with unique ID's(Site and Barcode). I can then create one to many relationships, which should solve the problem. I believe there should be an easier way....

     

 

Question:

What is the best way to do this:

  1. Use Power Query to create a lookup ID table from the Sales data? (This report is run every week, so constantly uses new data files)
  2. Is there a formula in Power Pivot Data Model that can sum the total value when the Site and Barcode match?
  3. How to create a lookup ID table that only includes distinct Site and Barcode from the Sales table in Power Pivot Model? (Without manually creating a table as mentioned above. I've only managed to use distinct with 1 column)

     

Image of Data Model layout:

VtS42.png

 

 

 

0 Replies