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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Same expression for calculated column and measure but different result

I have basically the same(I think they are the same, I could be wrong)expression for calculated colum and measure, yet it come out with complete different results:
 
Calculated column:
Adj Bse % = IF(BTA[D_EligibleBase_Units]<>0,DIVIDE(BTA[D_Base_Units],BTA[D_EligibleBase_Units]),0)
measure:
Adj bse% = IF(sum(BTA[D_EligibleBase_Units])<>0,DIVIDE(sum(BTA[D_Base_Units]),sum(BTA[D_EligibleBase_Units]),blank()))
 
Any idea why this occurred?
5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , A column Adj Bse % would be simple Average when take in visual

 

while measure DIVIDE(sum(BTA[D_Base_Units]),sum(BTA[D_EligibleBase_Units]) is correct allocated average

 

They are not same

Average(table, A/B) is not same sum(A)/Sum(B)

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Thank you for the quick reply, 

DIVIDE(A,B) will be how I want to put it, yet the result came out wrong in the calculated column, and it wont let me write like this in measure.

I dont understand why sum(A)/Sum(B) is right way to write it?

Hi @Anonymous ,

 

I think there may be duplicate key values like ID in your data table. Calcualted column will calculate by columns in each row, so you could only get the result from current row. However, measure could show you summarize result by sum/max function.

Here I build a sample to have a test by same code like yours.

You see in my data table, I have duplicate ID 1, so calcualte column will only return the result by row.

1.png

Measure should be the result you want.

2.png

If you want to get same result by calculated column, try this code.

 

Adj Bse% 2 =
VAR _D_Base_Units =
    CALCULATE ( SUM ( BTA[D_Base_Units] ), ALLEXCEPT ( BTA, BTA[ID] ) )
VAR _D_EligibleBase_Units =
    CALCULATE ( SUM ( BTA[D_EligibleBase_Units] ), ALLEXCEPT ( BTA, BTA[ID] ) )
RETURN
    IF (
        BTA[D_EligibleBase_Units] <> 0,
        DIVIDE ( _D_Base_Units, _D_EligibleBase_Units ),
        0
    )

 

1.png

Best Regards,
Rico Zhou

 

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

Anonymous
Not applicable

Thank you for the detail reply!

how do I know which column has been used as key value? and the way that my table set up are only having distinct values(My first colomn will be 1,2,3 instead of 1,1,2,3), shouldnt that fix the difference between measure and calculated colomns?

Hi @Anonymous ,

 

Key column is the column which you will use to build relationships in your data model, like ID in my Sample, categorys and so on. If ID is no duplicate (distinct 1,2,3), I think your code for calcualted column and measure will return the same result.

1.png

I couldn't reproduce your problem, please share a sample file with me and show me the result you want. This will make us easier to find the solution

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.