Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Row Context issues in IF compare

I have two tables: 'Ticket Comments Relations' and 'Tickets'.

In 'Tickets' I have a calculated column called Earliest Employee Comment that spits out an id based on some calculations. For example, this id could be 48985. I want to then in 'Tickets' create a calculated column that looks up this id in ''Ticket Comments Relations' and checks the value in [is_customer_comment] whether it is 0 or 1. If it's 1, then it does the calculation. If it's 0 then it returns -1 as the value instead. In our example, it would come out to be -1, and skip the long calculation. I keep getting the "A single value..." error as shown in the screenshot. What am I doing wrong? How do I provide a row context?

5 Replies

  • az38's avatar
    az38
    Icon for Community Champion rankCommunity Champion

    Hi Anonymous 

    for measures you should point out to exactly cell that you use in statement

    In your case you could replace IF(Table[Column], ...

    to IF(MAX(Table[Column]), ...

  • Anonymous , looking at the formula, you should create it as a column. Not measure

    • Anonymous's avatar
      Anonymous
      Not applicable

      It has always been a column. I haven't done anything related to measures.

      • sturlaws's avatar
        sturlaws
        Icon for Resident Rockstar rankResident Rockstar

        Hi Anonymous,

         

        From what I understand, you are creating the column [earliest employee comment] in the 'Ticket'-table. The way you have written your dax, you are not providing any context to the 'earliest employee comment'-table, and it tries to return all rows. If an ID is only present once in 'ticket comments relations', you can make use of LOOKUPVALUE(). If there is a relationship you can use RELATED().

        But if an ID can have both [is customer comment]=0 and [is customer comment]=1, you would have to do something like:

        earliest employee comment =
        IF (
            COUNTROWS (
                FILTER (
                    'ticket comments relations',
                    [is customer comment] = 1
                        && 'ticket comments relations'[target id] = tickets[id]
                )
            ) >= 1,
            MINX (
                FILTER (
                    'ticket comments relations',
                    'ticket comments relations'[target id] = tickets[id]
                        && 'ticket comments relations'[type] = 2
                ),
                'ticket comments relations'[comment id]
            ),
            -1
        )
        

         

        Cheers,
        Sturla

        If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

         

  • aj1973's avatar
    aj1973
    Icon for Community Champion rankCommunity Champion

    Anonymous 

    I would suggest, in your measure create a variable

    VAR = customer_comment = CONTAINS('Table','Table'[is_customer_comment], 1)

    then use the variable in your IF function