Forum Discussion

bacondrops's avatar
bacondrops
Frequent Visitor
3 years ago
Solved

DAX with multiple filters maybe?

GroupApplicationCompatibility Result
RetirementCash Cow 2.0Yes No
RetirementBlue Hair 3.1No  
InvestmentsCash Cow 2.0Yes No
InvestmentsBlue Hair 3.1No  
InvestmentsDoge Coin 1.9No  
InvestmentsWall Street 5.5No  
Real EstateZillow 9.4Yes Yes
Real EstateSell It All 1.0Yes  
Real EstateCrash 1.1Yes  
InsuranceCash Cow 2.0Yes Yes
InsuranceSell It All 1.0Yes  
InsuranceExistence 2.2Yes  
InsuranceNo Lizards 4.9Yes  

 

So, I have groups that contain different applications within each group.  And each application is marked as compatible (with something else outside this data set).  What I need to do is find out which Group has ALL of it's applications marked with a yes, and which Group has at least 1 no in it and spit those two results out into another column because if there's at least one application within a group that is NOT compatible, then I don't want to mark that Group as compatible.  The Result column above is what I'm looking for.  Hopefully that's clear, I feel like I stumbled through that explanation.  

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi bacondrops ,

    Please check if you use the correct table name in the formula. And you can create a calculated column or measure as below to get it, please find the details in the attachment.

    Calculated column:

    Result = 
    VAR _countyes =
        CALCULATE (
            COUNT ( 'Table'[Application] ),
            FILTER (
                'Table',
                'Table'[Group] = EARLIER ( 'Table'[Group] )
                    && 'Table'[Compatibility] = "Yes"
            )
        )
    VAR _countall =
        CALCULATE (
            COUNT ( 'Table'[Application] ),
            FILTER ( 'Table', 'Table'[Group] = EARLIER ( 'Table'[Group] ) )
        )
    RETURN
        IF ( _countyes = _countall, "Yes", "No" )

    Measure:

    Measure = 
    VAR _group =
        SELECTEDVALUE ( 'Table'[Group] )
    VAR _countyes =
        CALCULATE (
            COUNT ( 'Table'[Application] ),
            FILTER ( 'Table', 'Table'[Group] = _group && 'Table'[Compatibility] = "Yes" )
        )
    VAR _countall =
        CALCULATE (
            COUNT ( 'Table'[Application] ),
            FILTER ( 'Table', 'Table'[Group] = _group )
        )
    RETURN
        IF ( _countyes = _countall, "Yes", "No" )

    Best Regards

5 Replies

  • I understand how result is caluclated. But how do you want the final result to look like? Will this be a table visual? Only showing Group and Result?

     

    If this post was helpful, please kudos or accept the answer as a solution.
    ~ Anthony Genovese
    Need more PBI help? PM me for affordable, dedicated training or consultant recomendations!

    • AnthonyGenovese's avatar
      AnthonyGenovese
      Icon for Resolver III rankResolver III

      It's hard to give an exact dax calculation without knowing the exact tables and columns used, and what filters will be active on the report. But I would do something like this. Basically, count the rows in the group, removing all the filters on the same table except compatability, and then filter out Yes & No
      Result Measure =

      Var YesCnt = calculate(DistinctCount('TableName'[Group]), All('TableName'[Compatability]), 'TableName'[Compatability]="YES")
      Var NoCnt= IsBlank(calculate(DistinctCount('TableName'[Group]), All('TableName'[Compatability]), 'TableName'[Compatability]="No")
      var noBlankYes=if(isblank(yesCnt),0,yesCnt)

      var noBlankNo=if(isblank(noCnt),0,noCnt)
      var result = if(and(noBlankYes>0 ,noBlankNo=0),"YES","NO")
      return result

       

      If this post was helpful, please kudos or accept the answer as a solution.
      ~ Anthony Genovese
      Need more PBI help? PM me for affordable, dedicated training or consultant recomendations!

      • bacondrops's avatar
        bacondrops
        Frequent Visitor

        It's giving me the red squiggly lines on the last 3 variables - Var noBlankYes, Var noBlankNo, and Var result, as well as the Return result line.  It's an Unexpected Expression Var.