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
NickProp28
Post Partisan
Post Partisan

IF ELSE measures not returning 0

Dear Community, 

Good Day! 

 

NickProp28_1-1652928934427.png

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?

NickProp28_0-1652928877043.png

Expectation:

NickProp28_2-1652929085087.png

Any help will greatly appreciated. 

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

 

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @NickProp28 ,

Create measure.

CountNotBlank =
var _1=
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]
)
return
IF(
    _1 =BLANK(),0,_1)

Result:

vyangliumsft_0-1653315849450.png

If you need pbix, please click here.

 

Best Regards,

Liu Yang

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

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @NickProp28 ,

Create measure.

CountNotBlank =
var _1=
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]
)
return
IF(
    _1 =BLANK(),0,_1)

Result:

vyangliumsft_0-1653315849450.png

If you need pbix, please click here.

 

Best Regards,

Liu Yang

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

Ashish_Mathur
Super User
Super User

Hi,

Write this measure

Measure = coalesce([countnotblank],0)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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