DAX Power Pivot does order matter in multiplication

dicken

Active Member
Joined
Feb 12, 2022
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have posted a similar query on Excel Forum :

Excel Formula:
https://www.excelforum.com/office-365/1383891-dax-power-pivot-totals-using-sumx-and-related.html#post5704765

My question relates to the order you put things in a measure or calculated column where multiplication takes place
so;
t
Excel Formula:
ryone :=
SUMX (
    Sales,
    Sales[Sales]
        * ( RELATED ( 'Item'[Price] ) - RELATED ( 'Item'[Cost] ) )
        * ( 1 - RELATED ( Customer[Discount] ) )
)

Which works, but only two of the possible six permutations work, both ending on discount, the other four fail,
the other way is to use a summarized sales table ;

Excel Formula:
tryfour :=
SUMX (
    SUMMARIZE ( Sales, 'Item'[Cost], 'Item'[Price], Customer[Discount] ),
    ( 'Item'[Price] - 'Item'[Cost] ) * ( 1 - Customer[Discount] )
        * CALCULATE ( SUM ( Sales[Sales] ) )
)

Can someone explain why this happens and what the 'rules' are ?

Richard
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Multiplication order works the same way as mathematical rules. Order is not important

the first measure is inherently inefficient. i have a general guide. If you are using RELATED, in a measure, it’s probably not the best formula.

the second version is much better, because you are first generating the smallest possible virtual table, and are iterating over that.
 
Upvote 0
Multiplication order works the same way as mathematical rules. Order is not important

the first measure is inherently inefficient. i have a general guide. If you are using RELATED, in a measure, it’s probably not the best formula.

the second version is much better, because you are first generating the smallest possible virtual table, and are iterating over that.
Yes I accept the efficiency argument, but I am definitely getting different results ;
so if we take each part sales = s , price = cost = c and 1-discount = s
I have the following results ;;
scd = true
sdc = false
cds = false
csd= true
dsc = false
dcs = true

I have also put this measure on two sheets once on the sales table ;

SUMX(Sales,Sales[Sales]*(1-RELATED(Customer[Discount])*(RELATED('Item'[Price])- RELATED('Item'[Cost]) ) ) )
= 29.06 , which is incorrect

and again on the Customer table :

SUMX(Sales,Sales[Sales]*(-RELATED(Customer[Discount])*(RELATED('Item'[Price])-RELATED('Item'[Cost]) ) ) )
= -11.04,
I'd be interested in your comments, as I may be doing soemthing really stupid,
I've attached a link to a copy of the file on onedrive;


Richard
 
Upvote 0
Multiplication order works the same way as mathematical rules. Order is not important

the first measure is inherently inefficient. i have a general guide. If you are using RELATED, in a measure, it’s probably not the best formula.

the second version is much better, because you are first generating the smallest possible virtual table, and are iterating over that.
In response to my previous reply, 'yes' was doing something stupid, I had my bracketing wrong on the discount;
I'd made a mistake and repeated it, I kept forgetting a classing bracket . I have a habbit of this sort of thing, I once failed a maths exam not because my working out was wrong, I'd written down the wrong opening number . 🙄

Richard
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top