Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Division Quick Measure Issue

Hi there,

 

I am having an issue creating a quick measure. For example I am trying to divide Total Sales $ for Location Description by Total Linear. However, some locations have multiple SKUS in the underlying data.

 

For example, "Asst Squishmallows" has total lienar repeated 7 times causing it to divide Total Sales $ by 31.5 (4.5x7) not 4.5. I have also tried to link location description to another table but it causing a similar error. Is there a simple formula fix to this?

 

Essentially, I want all of the Sales $ to sum for the location description as it has been but only by the total linaer for the location description ($189,541/4.5).

 

Thanks for the help!

 

2 Replies

  • Hi Anonymous ,

     

    There's two ways that I can think to go about this:

     

    1) Group the table in Power Query before doing any calculations i.e. select any columns that have duplicated rather than unique values e.g. [Licence], [Location #], [Location Desc], [Total Linear] etc. then 'Group By' on the Home tab. In the UI that opens, select how you want to aggregate each of the unique value columns (probably SUM for each).

     

    2) A bit messier: you could include the count of duplicated rows within your measure to divide [Total Linear] by to get back to the single value, something along these lines may work:

    _salesPerLinear =
    VAR __linear =
    DIVIDE(
      SUM([Total Linear]),
      COUNT([Location Desc]),
      0
    )
    RETURN
    DIVIDE(
      SUM([Sales $]),
      __linear,
      0
    )

     

    However, I think this second option will only really work if you're adding context back in by reporting in a table with [Location Desc].

     

    Pete

  • v-lili6-msft's avatar
    v-lili6-msft
    Icon for Community Support rankCommunity Support

    hi Anonymous 

    It looks like a measure totals problem. Very common. See this post about it
    https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

    Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
    https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

     

    For your case, you could use this formula

    Measure = 
    DIVIDE(SUM('Table'[Sales $]), 
    SUMX(SUMMARIZE('Table','Table'[Location Description],'Table'[Total Linear]),[Total Linear])
           )

     

    or this simple formula

    Measure 2 = DIVIDE(SUM('Table'[Sales $]), AVERAGE('Table'[Total Linear]))

    Result:

     

    and here is a simple sample pbix file, please try it.

     

    Regards,

    Lin