Constantin Marguier
Constantin Marguier

Reputation: 11

Wrong general total in Power BI

I want to calculate the Herfindalh-Hirschmann Index (sum of market shares at square) by videogame publisher. In Power BI, i have 2 measures, the market share and the square of market share for each publisher. My calculations are good but the general total is false for the square of market share.

Issue with total

My DAX code is this for the Market Share (correct calculation & total) :

Market Share = VAR Volume = SUM('Sales - Global'[Sales])
VAR AllVolume = CALCULATE(SUM('Sales - Global'[Sales]), ALL('Publisher'))
RETURN DIVIDE(Volume, AllVolume)

My DAX code is this for the Squared Market Share. I ant to conserve the (*100) to better interprete the result. Calculations are good but the general total is incorrect. :

Market Share Square = 
VAR Volume = SUM('Sales - Global'[Sales])
VAR AllVolume = CALCULATE(SUM('Sales - Global'[Sales]), ALL('Publisher'[Publisher]))
VAR MarketShare = DIVIDE(Volume, AllVolume)*100
RETURN
    MarketShare * MarketShare

Upvotes: 0

Views: 32

Answers (1)

Sam Nseir
Sam Nseir

Reputation: 12111

You'll need to use SUMX to calculate the value for each row and then sum.

Market Share Square v2 = 
  var allVol = CALCULATE(SUM('Sales - Global'[Sales]), ALL('Publisher'[Publisher]))
  return SUMX(
    'Publisher',
    (
      var vol = CALCULATE(SUM('Sales - Global'[Sales]))
      var mktShare = DIVIDE(vol, allVol) * 100
      return mktShare * mktShare
    )
  )

Upvotes: 0

Related Questions