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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
JimmySXS
Regular Visitor

I have 2 DAX expressions that do the same thing except in one product caculation in 1000's

Hi,
First off I am learning DAXand using data sources found on the web to practice. I have created a model and was practicing my DAX and wrote 2 expressions that I thought did the same thing.
The first one 
Total Order Sales = SUMX(OrderLine, OrderLine[Sales] * OrderLine[Quantity])
then the next 2 to get the same value
Sales After Discount = SUMX(OrderLine, [Total Order Sales] *(1-OrderLine[Discount]))
Sales After Discount 2 = SUMX(OrderLine, (OrderLine[Sales] * OrderLine[Quantity]) * (1-OrderLine[Discount]))


It worked for 1000's of lines then not on 1 and I don't know why? Also I cannot find anywhere to attach the PBIX & xslx files I'm working from sorry.

Jim

JimmySXS_0-1739973133718.png

 

 




8 REPLIES 8
JimmySXS
Regular Visitor

Hi Guys thanks for your replies but I don't think the data is duplicated. Here is one of the products that is incomplete

JimmySXS_0-1740644631262.png

 

Anonymous
Not applicable

Thanks for the reply from LYPowerBI  and johnt75  , please allow me to provide another insight:

Hi, @JimmySXS 
Thanks for reaching out to the Microsoft fabric community forum.

Yes, as johnt75 mentioned and LYPowerBI verified, if the data itself contains duplicate rows, it can lead to inconsistent calculation results. The SUMX function inherently involves iteration. Below is a screenshot from the official documentation:

vlinyulumsft_0-1740119684639.png

vlinyulumsft_1-1740119684639.png

For more details, please refer to:

https://learn.microsoft.com/en-us/dax/sumx-function-dax#remarks

https://learn.microsoft.com/en-us/dax/dax-glossary#iterator-function

Here is my testing process:

1.This is my sample data:

vlinyulumsft_2-1740119758364.png

The red box highlights the obvious duplicate data.

 

2..Here are the final results:

vlinyulumsft_3-1740119758365.png

The results are inconsistent.

4.To modify this, you can try applying a DISTINCT() function to the Sales After Discount measure or the Total Order Sales measure before referencing the table. The final result is as follows:

vlinyulumsft_4-1740119771458.png

Please find the attached pbix relevant to the case.

 
Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
 

Best Regards,

Leroy Lu

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

 

LYPowerBI
Frequent Visitor

LYPowerBI_0-1739986872698.png

 

johnt75
Super User
Super User

I think that there are duplicate rows in your data, probably in the order line table but possibly in one of the tables order line is related to.

In your first sales after discount measure you are iterating over order line and then performing context transition by calling the [Total Order Sales] measure. That will put all copies of the duplicate rows into the filter context and you will get the sum of all those duplicates multiplied by the discount.

In the second version you are not forcing context transition, you are only iterating over the table once, so each duplicate row will only be counted once, not once per the number of duplicates.

On the attachment point, you can put files on Google Drive, OneDrive or similar and share them from there.

I tried to create a link like you suggested.

Download files 

I created a [Diff] measure to show when the 2 measures differed, and you can see that there is a difference on e.g. 29 August 2012. Looking at the order lines for that day, using

DEFINE
VAR _Date = TREATAS( { DATE( 2012,8,29) }, 'Calendar'[Date] )

EVALUATE
CALCULATETABLE(
	OrderLine,
	_Date
)
ORDER BY OrderLine[OrderID], OrderLine[ProductsID]

you can see that order ID 5907386 has a duplicate line for product 29. I'm sure there will be similar duplications for the other dates.

 

Hi,

 

Thank you for your quick reply. I stillcannot find a place to attach my files and now I cannot cfind anywhere to change my password as I forgotton it. 

JimmySXS

Anonymous
Not applicable

Hi, @JimmySXS 
 

Thank you for your prompt response.

 

If you need to upload a PBIX file, I recommend using SharePoint or GitHub and attaching the file link in your reply. Please ensure that any sensitive information is removed.

 

Here are some links on how to upload data:

How to provide sample data in the Power BI Forum - Microsoft Fabric Community

How to Get Your Question Answered Quickly - Microsoft Fabric Community

 

Best Regards,

Leroy Lu

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.