Equivalent of TSQL's IF EXISTS in DAX

I am looking for DAX's equivalent for TSQL's IF EXISTS.

Here is my table:

Name Flag
Emily 5
Victoria 5
Kimberly 5
John 4
Joe 5
Sam 5
Emily 4
Victoria 4
Sam 4
Emily 4
Victoria 5

and here is my TSQL query:
select count (distinct (name))
from table1 t1
where
  flag = 5
  and exists (select * from table1 t2 where t1.name=t2.name and flag=4)

It should return 3 (Emily, Victoria and Sam).

Basically, I am looking for count distinct name for rows that have flag=5 and at least have one flag=4 for the same person. Maybe it can also be described as union between two tables table1 for flag=5 and table2 for flag=4.

Can we do this in DAX?

Thanks

 
July 2nd, 2014 10:35am

Hi,

Just like If exists we have Contains in DAX.

The CONTAINS function just checks the existence, in
the table passed as first parameter, of at least one row that contains all the column values specified in
the following parameters. This is the syntax.
CONTAINS( <table>,
          <column1_name>, <column1_expression>
          [,<column2_name>, <column2_expression>]
          [, ] )

Thanks

Free Windows Admin Tool Kit Click here and download it now
July 3rd, 2014 5:18am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics