Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Power BI desktop

Hi,

Hope you all are doing well!

If am trying to create a column using 'if'. The condition is this if number of participants found in the table then it shows some value, otherwise 0. Somehow, I am not getting the desired ouput.

 

Table 1:

CountryCityParticipants
ABCGHJYes
DHHKJLNo
ABCDEFYes
BNMJKLYes
ABCDEFYes

 

New Column = if (Table 1[Country]= "ABC" && Table 1[City] ="DEF",COUNT(Table1[Participants]),0)
The output of the above query should be '2'
Can anyone tell me what's wrong with this query.
  • Hi Anonymous 

     

    Try this code to add a new column:

    Column = 
    Var _A = filter(all('Table 1'),'Table 1'[Country]=EARLIER('Table 1'[Country])&&'Table 1'[City]=EARLIER('Table 1'[City]))
    Var _B = COUNTROWS(_A)
    return
    if(_b>1,_B,0)

     

    output:

     

     

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/

     

     

1 Reply

  • Hi Anonymous 

     

    Try this code to add a new column:

    Column = 
    Var _A = filter(all('Table 1'),'Table 1'[Country]=EARLIER('Table 1'[Country])&&'Table 1'[City]=EARLIER('Table 1'[City]))
    Var _B = COUNTROWS(_A)
    return
    if(_b>1,_B,0)

     

    output:

     

     

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/