If I bring in all the sales details I'm not sure how to reconcile that with my in stock data. My sales details are stored per sales line so I have many entries for the same article number, whereas my in stock data is stored with one entry per article number.Here's the query I use to get the consolidated results by brand:SELECT c.Brand, a.[MTDSales], a.[MTDCost], a.[MTDMargin], SUM(fis.InStockValue) FROM FactStockTable b INNER JOIN dimArticle c ON b.ArtNo = c.ArtNo INNER JOIN (SELECT c.Brand, CAST(SUM(d.LineAmount) AS decimal(10, 0)) AS [MTDSales], CAST(SUM(d.Cost) AS decimal(10, 0)) AS [MTDCost], 1 - SUM(d.Cost) / NULLIF (SUM(d.LineAmount), 0) AS [MTDMargin] FROM FactSalesTable d INNER JOIN dimArticle AS i ON d.ArtNo = c.ArtNo INNER JOIN dimDates AS d ON d.SalesDate = d.DateID INNER JOIN (SELECT CONVERT(CHAR(7), DATEADD(mm, 0, DATEADD(mm, 0, GETDATE())), 120) AS timeframe) AS t ON d.YrMth = t.timeframe GROUP BY c.Brand) a ON c.Brand = a.BrandWHERE c.Brand = @BrandNameGROUP BY c.Brand , a.[MTDSales], a.[MTDCost], a.[MTDMargin]
My query to get the data by supplier looks almost identical, substituting brand with supplier. Am I not approaching this correctly? Thanks.