1
votes

I am a heavy user of R who is trying to port some basic calculations to Power BI but unable to get DAX to perform vector/rowwise division.

For example, with this dataset:

Category Value

A 1

A 2

B 3

C 4

I have created a measure: Value Sum = SUM(Table[Value]) and I would like to create a third column: Value Share = Value / Value Sum to get:

Category Value Value Share

A 1 0.1

A 2 0.2

B 3 0.3

C 4 0.4

The equivalent in R would be table$Value.Share = table$value/Value.Sum.

I have tried: Value Share = [Value] / [Value Sum] but I ended up with 1s in all Value Share rows. Tried SUMX and CALCULATETABLE functions but I believe I am missing something fundamental. Can anyone help?

2

2 Answers

1
votes

Sure! If you're starting out with DAX, I can highly recommend to view one of the video lectures of Alberto Cairo / Marco Russo like https://www.youtube.com/watch?v=klQAZLr5vxA, because your question (and all of DAX difficulty) is primarily about contexts.

As for your question, I think you're looking for

=[Value]/CALCULATE(SUM([Value]); ALL(TableName))

Of course, you can replace SUM([Value]) with a measure name too.

See also http://www.daxpatterns.com/cumulative-total/

0
votes

try this formula: divide([value],sum([value]))

SNAP of DAX formula