Nick
Nick

Reputation: 81

IF ELSE measures not returning 0

Good Day! enter image description here

This is my code criteria, for the highlighted row, it will count ETD and ATD if there is value, but since there is none, it will return 0 and 0% for the calculation.

This is my measure,

CountNotBlank = 
SUMX(
ADDCOLUMNS(
RawDatas,
"Count",
var Direction = RawDatas[Direction]
var Dep = RawDatas[Dep]
var res1 = COUNTROWS(
FILTER(
 {RawDatas[ETD],RawDatas[ATD],RawDatas[ETA],RawDatas[ATA],RawDatas[Estimated Delivery],RawDatas[Actual Delivery]},
NOT ISBLANK([Value])))
var res2 = COUNTROWS(
FILTER(
 {RawDatas[ETA],RawDatas[ATA],RawDatas[Estimated Delivery],RawDatas[Actual Delivery]},
NOT ISBLANK([Value])) )
var res3 = COUNTROWS(
filter(
 {RawDatas[ETD] , RawDatas[ATD]},
NOT ISBLANK([Value]) ))
var res4 = COUNTROWS(
FILTER(
 {RawDatas[ETA],RawDatas[ATA]},
NOT ISBLANK([Value])))
return
if (Direction = "Export" && LEFT(Dep, 1) = "D", res2 , 
if (Direction = "Export" && NOT(LEFT(Dep, 1) = "D") , res1,
if (Direction = "Import" , res3,
if (Direction = "Domestic" , res4,
0))))),
[Count])

I tried returning 0 if a condition isn't met, but it doesn't seem to work. Is there anything I missed? enter image description here

Expectation enter image description here

Any help will greatly appreciated.

Attached with the pbix: https://drive.google.com/file/d/1aHV6qz66yPMbqR34EdCEGd3UPK_lsStv/view?usp=sharing

Upvotes: 1

Views: 137

Answers (1)

alexfeuch
alexfeuch

Reputation: 51

I was able to produce your expected result by nesting the whole expression inside IF(ISBLANK(...:

CountNotBlank = 
VAR notblankvar = 
//your code from above not pasted here for readability//
RETURN IF(ISBLANK(notblankvar),0,notblankvar)

Let me know if it would be helpful to see my .pbix file.

Upvotes: 1

Related Questions