Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
JO8930
New Member

sql

Why the difference?

SELECT SUM([CategorySalesBudget])
FROM [dbo].[SubCategorySalesBudgetPSPD]
WHERE TransDate BETWEEN '2025-04-01' AND '2025-06-30';= 27,945,373,588.89


And this:
SELECT
b.[StoreID],
s.[StoreName],
MONTH([TransDate]) AS [Month],
p.[Section],
p.[Department],
p.[Category],
SUM([CategorySalesBudget]) AS [BudgetSales]
FROM [dbo].[SubCategorySalesBudgetPSPD] b
INNER JOIN ProductDim p ON b.[Subcategory] = p.[Subcategory]
INNER JOIN StoreDim s ON b.[StoreID] = s.[StoreID]
WHERE [TransDate] BETWEEN '2025-04-01' AND '2025-06-30'
GROUP BY b.[StoreID], s.[StoreName], p.[Section], p.[Department], p.[Category], MONTH([TransDate]);

= 4,647,274,218,492.51

2 ACCEPTED SOLUTIONS
nilendraFabric
Super User
Super User

Hello @JO8930 


The first query simply sums the CategorySalesBudget values directly from the SubCategorySalesBudgetPSPD table with just a date filter

 

The second query joins the SubCategorySalesBudgetPSPD table with ProductDim and StoreDim tables before summing, which can cause multiplication of values

 

Check for duplicate keys in your dimension tables and ensure they have unique Subcategory and StoreID values. and Use DISTINCT in your JOIN keys

View solution in original post

v-tsaipranay
Community Support
Community Support

Hi @JO8930 ,

Thanks for reaching out to the Microsoft Fabric Community. Also thank you @nilendraFabric  for correctly pointing out the cause.

 

The large difference you're seeing is due to the JOINs in the second query, which can duplicate rows if the dimension tables (ProductDim or StoreDim) contain multiple matching entries for the same Subcategory or StoreID. These duplicates inflate the SUM(CategorySalesBudget).

To resolve this, please verify that the dimension tables contain unique keys for the join fields. If not, you may need to review the data model or apply deduplication before joining.

 

If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.

 

Thankyou.

View solution in original post

2 REPLIES 2
v-tsaipranay
Community Support
Community Support

Hi @JO8930 ,

Thanks for reaching out to the Microsoft Fabric Community. Also thank you @nilendraFabric  for correctly pointing out the cause.

 

The large difference you're seeing is due to the JOINs in the second query, which can duplicate rows if the dimension tables (ProductDim or StoreDim) contain multiple matching entries for the same Subcategory or StoreID. These duplicates inflate the SUM(CategorySalesBudget).

To resolve this, please verify that the dimension tables contain unique keys for the join fields. If not, you may need to review the data model or apply deduplication before joining.

 

If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.

 

Thankyou.

nilendraFabric
Super User
Super User

Hello @JO8930 


The first query simply sums the CategorySalesBudget values directly from the SubCategorySalesBudgetPSPD table with just a date filter

 

The second query joins the SubCategorySalesBudgetPSPD table with ProductDim and StoreDim tables before summing, which can cause multiplication of values

 

Check for duplicate keys in your dimension tables and ensure they have unique Subcategory and StoreID values. and Use DISTINCT in your JOIN keys

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Free Fabric Certifications

Free Fabric Certifications

Get Fabric certified for free! Don't miss your chance.

January Fabric Update Carousel

Fabric Monthly Update - January 2026

Check out the January 2026 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.