Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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?

Screenshot 2020-07-13 at 16.14.43.pngScreenshot 2020-07-13 at 16.16.29.png

5 REPLIES 5
amitchandak
Super User
Super User

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

Anonymous
Not applicable

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

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
Community Champion
Community 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

 

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

az38
Community Champion
Community 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]), ...


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.