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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Tiger2514555
Helper III
Helper III

Total measurement was incorrect because the calculation of blank values.

The problem is that if 1 is blank it is negative. If 2 is blank it is positive. I want them to be 0 if don't have 1 and 2 to show the correct total as I want. 
Tiger2514555_1-1700713185312.png

My DAX for sum:

Compare Realtime Snapshot =
VAR FilterTable =
    FILTER(
        'Inventorys',
        'Inventorys'[item] = 'Inventorys'[item] &&
        ('Inventorys'[FilterType] = 1 || 'Inventorys'[FilterType] = 2)
    )

VAR Real =
    SUMX(
        FILTER(
            FilterTable,
            'Inventorys'[FilterType] = 1
        ),
        'Inventorys'[qtyOnHand]
    )

VAR Snap =
    SUMX(
        FILTER(
            FilterTable,
            'Inventorys'[FilterType] = 2
        ),
        'Inventorys'[qtyOnHand]
        )
  
VAR Sum_total = Real-Snap
RETURN
    Sum_total
3 REPLIES 3
lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

My sample data:

itemType1Type2total
a2-20
b1 1
c -3-3
d6-33
e4-5-1

I don't want the calculation to occur when there are blank values ​​and the total for that row must be 0.
@lbendlin 

The results I want:

itemType1Type2total
a2-20
b1 0
c -30
d6-33
e4-5-1

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTICYl0jpVidaKUkINMQiBXAvGQwCyhpDOamAJlmCG4qkGkC4poqxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [item = _t, Type1 = _t, Type2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"item", type text}, {"Type1", Int64.Type}, {"Type2", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "total", each if [Type1]=null or [Type2]=null then 0 else [Type1]+[Type2],Int64.Type)
in
    #"Added Custom"

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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