Forum Discussion

AutoKris's avatar
AutoKris
Frequent Visitor
2 years ago
Solved

Measure counting unique Report Key based on values in another column

Hi, I tried to solve it with DAX Calculate, with FIlters and Counting Rows, however cannot get my head around it, even ChatGPT 3.5 nor Bing Chat were able so simply solve this. I think this is easy ...
  • Greg_Deckler's avatar
    2 years ago

    AutoKris Try this. PBIX is attached below signature. I guess my job is safe from AI for now...

    Measure = 
        VAR __Good = { "R1" }
        VAR __Table = FILTER( 'Table', [Comment] <> BLANK() )
        VAR __Bad = DISTINCT(SELECTCOLUMNS(FILTER( __Table, NOT( [Comment] IN __Good ) ), "__Comment", [Comment] ) )
        VAR __BadKeys = SELECTCOLUMNS( FILTER( 'Table', [Comment] IN __Bad), "__ReportKey", [Report Key] )
        VAR __GoodKeys = DISTINCT( SELECTCOLUMNS( FILTER( 'Table', NOT( [Report Key] IN __BadKeys ) ), "__Key", [Report Key] ) )
        VAR __Result = COUNTROWS( __GoodKeys )
    RETURN
        __Result