none
T-SQL equivalent to DAX RRS feed

  • Question

  • Hi,

    Can anyone help on writing below T-SQL code into DAX

    SELECT OrderDate,SUM(SalesAmount) AS Sales
    FROM  FactSales
    GROUP BY OrderDate

    
    
    
    
    Monday, November 23, 2015 9:19 AM

Answers

  • Please try like below

    EVALUATE
    SUMMARIZE (
        FactSales,
        FactSales[OrderDate],
        "Sales", SUM ( FactSales[SalesAmount] )
    )
    
    OR
    
    EVALUATE
    ADDCOLUMNS (
        VALUES ( FactSales[OrderDate] ),
        "Sales", CALCULATE ( SUM ( FactSales[SalesAmount] ) )
    )


    Cheers,

    Amit Tomar

    ---------------------------------------------------

    Please mark this as answer if it solved your query

    Please vote this as helpful if it solved your query

    ---------------------------------------------------

    My Blog My Wiki Page

    Monday, November 23, 2015 9:24 AM
  • Definitely prefer the second version to the first.

    SUMMARIZE() can have unintuitive behavior at times, and is usually significantly less performant than ADDCOLUMNS() for the purpose of projecting an extension column. SUMMARIZE() is typically best used only for grouping by columns.

    See this article for more detail around the performance concerns of adding extensions columns within SUMMARIZE().

    GNet Group BI Consultant

    Monday, November 23, 2015 4:53 PM

All replies

  • Please try like below

    EVALUATE
    SUMMARIZE (
        FactSales,
        FactSales[OrderDate],
        "Sales", SUM ( FactSales[SalesAmount] )
    )
    
    OR
    
    EVALUATE
    ADDCOLUMNS (
        VALUES ( FactSales[OrderDate] ),
        "Sales", CALCULATE ( SUM ( FactSales[SalesAmount] ) )
    )


    Cheers,

    Amit Tomar

    ---------------------------------------------------

    Please mark this as answer if it solved your query

    Please vote this as helpful if it solved your query

    ---------------------------------------------------

    My Blog My Wiki Page

    Monday, November 23, 2015 9:24 AM
  • Definitely prefer the second version to the first.

    SUMMARIZE() can have unintuitive behavior at times, and is usually significantly less performant than ADDCOLUMNS() for the purpose of projecting an extension column. SUMMARIZE() is typically best used only for grouping by columns.

    See this article for more detail around the performance concerns of adding extensions columns within SUMMARIZE().

    GNet Group BI Consultant

    Monday, November 23, 2015 4:53 PM