Forum Discussion

amon151's avatar
amon151
Frequent Visitor
4 years ago
Solved

Countif for dynamic criteria range

Hello!   I'm trying to replicate the excel COUNTIF function in DAX. I basically want to count the number of instances each value of column B appears in column A range.   Excel Formula =COUNTIF($...
  • SpartaBI's avatar
    4 years ago

    amon151  if a column then this is the code: 

     

    Output = 
    VAR _b = 'Table'[Column B]
    VAR _result = 
    COUNTROWS(
        FILTER(
            'Table',
            'Table'[Column A] = _b
        )
    )
    RETURN
        _result

     

     

     

    If a measure then this:

     

    Output Measure = 
    VAR _b = SELECTEDVALUE('Table'[Column B])
    VAR _result = 
    COUNTROWS(
        FILTER(
            ALL('Table'),
            'Table'[Column A] = _b
        )
    )
    RETURN
        COALESCE(_result, "")

     

     





          

    Showcase Report – Contoso By SpartaBI