Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
wanyunyang
Creator III
Creator III

Handle NULL in calculation.

Hi guys,

Here's what my raw data looks like:

Capture.PNG

Order A is divided into sub orders a,b,NULL. I want to calculate the net sales of A, which should be 2+3+4=9. I wrote this formula in Qlik Sense:

SUM(Netsales)/COUNT(DISTINCT SubOrders)

But the result is NULL. How can I fix this?

Thanks for help!

15 Replies
wanyunyang
Creator III
Creator III
Author

thanks anyway

JustinDallas
Specialist III
Specialist III

When you load your data, can you do an "If( IsNull(MyField), 1 )" test?  Because I've got this test data and it appears to be working for me.

OrderStuff:

LOAD *,

If( SubOrdersString = 'NULLME', Null(), SubOrdersString ) AS  SubOrders

;

LOAD * Inline

[

Order, SubOrdersString, NetSales

    A, a, 2

    A, a, 3

    A, a, 4   

    A, b, 2   

    A, b, 3

    A, b, 4

    A, 'NULLME', 2

    A, 'NULLME', 3

    A, 'NULLME', 4

]

;

DROP FIELD SubOrdersString

;

EXIT Script

;

Capture44.PNG

wanyunyang
Creator III
Creator III
Author

Worked! Thanks!

Anonymous
Not applicable

I still don't understand qhy you got a dash as return value...

isingh30
Specialist
Specialist

Please check this. Let me know.

Thanks.

wanyunyang
Creator III
Creator III
Author

I think it doesn't treat all the NULLs as a group.