Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
SiGill1979
Frequent Visitor

Dax Measure dividing the sum of one column by the sum of another

Hi

Hope someone can help. I've got the following Measure

GM% = if(DIVIDE(SUM(ProfitabilityMASTERFinal[GM]),SUM(ProfitabilityMASTERFinal[Net Sales]))>9.9999,9.9999,IF(DIVIDE(SUM(ProfitabilityMASTERFinal[GM]),SUM(ProfitabilityMASTERFinal[Net Sales]))<-9.9999,-9.9999,DIVIDE(SUM(ProfitabilityMASTERFinal[GM]),SUM(ProfitabilityMASTERFinal[Net Sales]))))
 
If I then add this measure to a table and and the Year column in, I get the same result for all years. How do I get it to give me the correct result for each year. Is there a Partition By or Over function in Power BI?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @SiGill1979 ,

 

Do you have any other fields on your form besides [Year] because sum() will group based on the fields placed on the form Visual.

If you want to group based on the [Year] field, you can place only [Year] and measure in the Form Visual.

If you have the rest of the fields and the [Year] field in Form Visual, and you want to group by [Year] field, you can change the measure。

Measure 2 =
var _sumGM=
SUMX(FILTER(ALL('ProfitabilityMASTERFinal'),'ProfitabilityMASTERFinal'[Year]=MAX('ProfitabilityMASTERFinal'[Year])),[GM])
var _sumnet=
SUMX(FILTER(ALL('ProfitabilityMASTERFinal'),'ProfitabilityMASTERFinal'[Year]=MAX('ProfitabilityMASTERFinal'[Year])),[Net Sales])
RETURN
 if(
    DIVIDE(_sumGM,_sumnet)>9.9999,9.9999,IF(DIVIDE(_sumGM,_sumnet)<-9.9999,-9.9999,DIVIDE(_sumGM,_sumnet)))

 

vyangliumsft_0-1709689460968.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @SiGill1979 ,

 

Do you have any other fields on your form besides [Year] because sum() will group based on the fields placed on the form Visual.

If you want to group based on the [Year] field, you can place only [Year] and measure in the Form Visual.

If you have the rest of the fields and the [Year] field in Form Visual, and you want to group by [Year] field, you can change the measure。

Measure 2 =
var _sumGM=
SUMX(FILTER(ALL('ProfitabilityMASTERFinal'),'ProfitabilityMASTERFinal'[Year]=MAX('ProfitabilityMASTERFinal'[Year])),[GM])
var _sumnet=
SUMX(FILTER(ALL('ProfitabilityMASTERFinal'),'ProfitabilityMASTERFinal'[Year]=MAX('ProfitabilityMASTERFinal'[Year])),[Net Sales])
RETURN
 if(
    DIVIDE(_sumGM,_sumnet)>9.9999,9.9999,IF(DIVIDE(_sumGM,_sumnet)<-9.9999,-9.9999,DIVIDE(_sumGM,_sumnet)))

 

vyangliumsft_0-1709689460968.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

lbendlin
Super User
Super User

That would be a question for your data model wiring.  Same value in all rows = can't get there from here (for example you are trying to control a dimension from a fact).  Which columns did you use for the visual?

 

By the way your measure can be simplified either via variables or via MinMax:

 

GM% =
MAX (
    MIN (
        DIVIDE (
            SUM ( ProfitabilityMASTERFinal[GM] ),
            SUM ( ProfitabilityMASTERFinal[Net Sales] ),
            0
        ),
        9.9999
    ),
    -9.9999
)

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.