Forum Discussion

MDR's avatar
MDR
Frequent Visitor
3 years ago

Convert SQL query to a DAX measure, calculate sum for distinct values in another column

What is an equivalent DAX measure for the following SQL query:

 

select sum(amount) from (select distinct srcid, amount from mytable where datanameshort='name' and status = 'status');

3 Replies

  • MDR's avatar
    MDR
    Frequent Visitor
     
    SUMX (VALUES('Table'[Amount] ), CALCULATE(DISTINCT('Table'[Scrid] ), 'Table'[datanameshort]="name'"&& 'Table'[status] = "status"))
  • Hi MDR ,
    Try this.
    SUMX (
    SUM( 'Table'[Amount] ),
    CALCULATE ( DISTINCT ( 'Table'[Scrid] ) , 'Table'[datanameshort]='name' and 'Table'[status] = 'status)
    )
    Thanks,
    Pratyasha Samal
    Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
    If you found this post helpful, please give Kudos C

    • MDR's avatar
      MDR
      Frequent Visitor

      Thanks pratyashasamal this returns the following error:

      The SUMX function expects a table expression for argument '1', but a string or numeric expression was used.