Forum Discussion

Nightlight's avatar
Nightlight
New Member
8 years ago

If+countifs in PowerBI

Actually, I have met a problem about how to filter the special column by criterias.In Exccel,if+Countifs is easy.


City Transportation Metro?
Beijing Air Yes
Beijing Metro Yes
Beijing Train Yes
Shanghai Air Yes
Shanghai Metro Yes
Shanghai Train Yes
Nanchang Air No
Nanchang Train No


so my question is : how to get column"Metro?" by DAX functions?

1 Reply

  • Nightlight,

     

    Try this calculated column:

     

    Metro = 
    VAR vCity = MetroTest[City]
    VAR vMetroRowCount =
        FILTER (
            MetroTest,
            MetroTest[City] = vCity
                && MetroTest[Transportation] = "Metro"
        )
    VAR vResult =
        IF ( COUNTROWS ( vMetroRowCount ) > 0, "Yes", "No" )
    RETURN
        vResult