Forum Discussion

ricardo_cvo's avatar
ricardo_cvo
Icon for Helper I rankHelper I
8 years ago

Dax Sales by Period

Good afternoon everyone,


I am new to dax and need to get the sum of sales as follows:
Sales from day 1 to day 30
Sales from the 31st to the 60th
It's possible?


Thank you

21 Replies

  • gregcd's avatar
    gregcd
    Frequent Visitor

    Can you attach a screenshot of the data you are working with 

  • HI Ricardo,

     

    Check the following if it works:

     

    Sales 1 to 30 Days = CALCULATE([Sum Sales], DATESBETWEEN(dCalendar[Date],MAX(fSales[Date of Sale])-60,MAX(fSales[Date of Sale])-30))

     

    Sales 31 to 60 Days = CALCULATE([Sum Sales], DATESBETWEEN(dCalendar[Date],MAX(fSales[Date of Sale])-30,MAX(fSales[Date of Sale])))

     

    Thanks,

    Sandeep

    • ricardo_cvo's avatar
      ricardo_cvo
      Icon for Helper I rankHelper I

      Thanks for the feedback,

       

      I tested the Sales 31 to 60 Days formula that in the example is from 06/13 to 07/07 and is giving 123537,10 how much the value should be 118692.82.

       

      Regards

      • Washivale's avatar
        Washivale
        Icon for Resolver V rankResolver V

        Hi Ricardo,

         

        Please give it a try with below measures.

         

        Sales 31 to 60 Days =

        var ld = CALCULATE ( MAX ( dCalendar[Date] ), ALLSELECTED ( dCalendar[Date] ))
        var sd = ld-30
        return
        CALCULATE([Sum Sales], DATESBETWEEN(dCalendar[Date],sd,ld))

         

        Sales 1 to 30 Days =
        var ld = CALCULATE ( MAX ( dCalendar[Date] ), ALLSELECTED ( dCalendar[Date] ))
        var sd = ld-60
        var lp = sd + 30
        return
        CALCULATE([Sum Sales], DATESBETWEEN(dCalendar[Date],sd,lp))

         

        let me know if it works