Forum Discussion

IvanMislav's avatar
IvanMislav
Helper I
7 years ago

Dynamic label based on custom measure

Hi, i have a simple data model. Something like company name, income, expenses.

 

I created a custom measure Balance = income - expenses.

 

What I want to do is create a dynamic lable: 

  •  if balance < 0 = "Negative"
  • if balance >= 0 = "Positive"

Finally, I want to have a number of companies by type.

 

I wrote a measure "Number of negative companies" = CALCULATE(DISTINCTCOUNT(data[CompanyName]);Balance<0) and I get an error saying "A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

 

What am I doing wrong?

 

Thank you!

 

 

5 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    You could do this:

     

    Label = 
    SWITCH(TRUE(),
        [Balance]<0,"negative",
        [Balance]>0,"positive",
        "zero"
    )
    
    NegativeCount = 
    VAR __table = SUMMARIZECOLUMNS('Table19'[Company],'table19',"__balance",[Balance])
    RETURN
    COUNTX(FILTER(__table,[__balance]<0),[Company])

    See attached Table 19, Page 11