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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Kimbornhoft
Helper I
Helper I

Incorrect calculated measure total

Hi,

 

I have a new measure 

 

Total Shipped Value = (sum(REV_HistoryReport[Total Li Valu Amt]) /sum(REV_HistoryReport[Ord Bill Unit Qty]) * sum(OpenOrders[Qty Filled]))

 

which works correctly except when the OpenOrders[Qty Filled] field is a 0. Zero is returned but the cumulative total is not correct.  How do I add in an If/Then statement which says complete the calculation except when a 0 is present, then just return a 0? Or do I change the 0 in the OpenOrders[Qty Filled] field to a dash so that it isn't recognized as a number and just skips it.

 

Thanks for the help. 

 

 

21 REPLIES 21
GilbertQ
Super User
Super User

Hi @Kimbornhoft

 

Ideally you can use the new DIVIDE DAX function, which will allow you to set a figure when there is a divide by zero error.

 

Total Shipped Value =
DIVIDE (
    SUM ( REV_HistoryReport[Total Li Valu Amt] ),
    SUM ( REV_HistoryReport[Ord Bill Unit Qty] ) * SUM ( OpenOrders[Qty Filled] ),
    0
)

This will return a zero if there are no values.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Thank you for replying, unfortunately, this formula returned all lines as $0.

Anonymous
Not applicable

@GilbertQ is correct in that using DIVIDE( ) is a good idea to avoid divide by zero errors.   But in your case, you are just doing something "mathematically wrong".

 

Quantity    Price   SubTotal

2                3         6

3                4         12

 

Here the total is 18 (6+12), it is not  sum(quant) * sum(price) = 5 * 12 = 60.

 

think you have something similiar going on?  Think we will need to see some sample data.


You might try:

Total Shipped Value = SUMX(REV_HistoryReport, CALCULATE(sum(REV_HistoryReport[Total Li Valu Amt])/sum(REV_HistoryReport[Ord Bill Unit Qty]) * sum(OpenOrders[Qty Filled])))

This solves the issue 99% of the time. Here is an exception:  the correct total is $59,051 but Power BI is doubling that total when an item appears muliple times to $118,102.

3131BE1/10/2017$29,526189
3131BE1/10/2017$29,526189

 

 

 biimage.png

 

 

 

Anonymous
Not applicable

I'm not totally sure which table we are talking about, but... errr, uhh... if we are talking about double rows in REV_HistoryReport,  maybe inside the CALCULATE  divide by COUNTROWS(REV_HistoryReport) ?

I have used this string,

 

Total Shipped Value = SUMX(REV_HistoryReport, CALCULATE(sum(REV_HistoryReport[Total Li Valu Amt])/sum(REV_HistoryReport[Ord Bill Unit Qty]) * sum(OpenOrders[Qty Filled])))

 

but I'm not sure where to incorporate the count rows  Could you help with this?

 

 

You were right in assuming it is the REV history report.

Anonymous
Not applicable

Total Shipped Value =
SUMX (
    REV_HistoryReport,
    CALCULATE (
        SUM ( REV_HistoryReport[Total Li Valu Amt] )
            / SUM ( REV_HistoryReport[Ord Bill Unit Qty] )
            * SUM ( OpenOrders[Qty Filled] )
/ COUNTROWS(REV_HistoryReport)
    )
)

Unfortunately, formula still isn't returning the correct values. I'm not sure where to go next.

2017-05-26_14h21_49.jpgHi

 

I'm going back to the beginning. Unfortunately, the suggestions above have not worked. All of the values in this table are correct except for the new measure field. It should be $2,260,502. The new measure is

 

Total Shipped Value = (sum(REV_HistoryReport[Total Li Valu Amt]) /sum(REV_HistoryReport[Ord Bill Unit Qty]) * sum(OpenOrders[Qty Filled]))

 

 

 

 

It seems to be related to the math that happens when a qty filled column is 0.

Anonymous
Not applicable

Maybe already answered above, but double checking here... your Total Shipped Value... is that a measure or a calculated column?

It is a measure.

 

Anonymous
Not applicable

Ya, that won't math correctly.  If math was a verb.

 

1  2

2  3

3  4

 

(1+2+3) * (2 + 3 + 4) = 6 * 9 = 54.

(1*2) + (2*3) + (3*4) = 2 + 6 + 12 = 20.

 

You want the latter, but are doing the fomer.

 

I would think...

 

Total Shipped Value = sumx(REV_HistoryReport, REV_HistoryReport[Total Li Valu Amt]) / REV_HistoryReport[Ord Bill Unit Qty] * OpenOrders[Qty Filled])

 

But... I'm skeptical that is going to handle OpenOrders correctly.  How are those tables related?

I've tried this measure but it includes this error message2017-05-26_15h30_06.jpg

Anonymous
Not applicable

Okay, so those tables are not (directly) related.  I would call them independent fact tables.

 

 

I had a stray paren somewhere, I would think this:

Total Shipped Value := SUMX (
    REV_HistoryReport,
    REV_HistoryReport[Total Li Valu Amt] / REV_HistoryReport[Ord Bill Unit Qty]) * OpenOrders[Qty Filled]

So, take the avg $ amt (total amt / unit quantity) ... and multiple by the qty of filled orders?   That reads ok.

Hello,

 

Thanks so much for replying. This is the error message that I get when I use that formula.

 

A single value for column 'Qty Filled' in table 'OpenOrders' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

2017-05-26_14h51_55.jpg2017-05-26_14h52_23.jpg

We thought it would work to create a relationship between the open orders and the Rev_HistoryReport based on the MMMID but we get this error message. 2017-05-26_15h13_34.jpg

Is there anything else you need to understand the relationships. Thanks for your help. I'm a novice at Power BI so your help is very much appreciated.

Here are the relatio2017-05-26_14h50_09.jpgnships

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.