Quantcast
Channel: SCN : Blog List - All Communities
Viewing all articles
Browse latest Browse all 2548

Possible Pitfall when multiplying/dividing measures and how to avoid it

$
0
0

Hello everyone,

I´m sorry if you all are aware of it, but I think it deserves some attention :

 

 

This is my query over e-fashion

 

 

query.png

 

What I´ll do here is calculating  the unitary price for a product in a Line in the dumbiest way :

Just dividing [Sales revenue] by [Quantity sold] for each [Year]. This gives me the following table

 

 

 

 

 

report.png

So far so good ...

But what if I took [Year] away from my table ?

Here´s what happens

 

report def calc.png

 

As you can see, the values are different but why this happens ?

BO adds another rule of precedence when calculating values, besides the * / + - precedence , there is the default aggregation of the measure that is with greater precedence.

So, when calculating =[Sales revenue]/[Quantity sold], what is really been calculated is =Sum([Sales revenue])/Sum([Quantity sold]).

 

In order to avoid this problem, you better add back the missing dimmension (in this case, [Year]) through the use of the ForEach operator

 

=Sum( ([Sales revenue]/[Quantity sold]) ForEach ([Year]))/3. Like in the table below

 

report full.png

 

 

 

 

So when dealing with multiplication/division of Measures, always remember  to use ForEach operator.

Regards,

Rogerio


Viewing all articles
Browse latest Browse all 2548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>