Forum Discussion

Catherine84's avatar
Catherine84
Icon for Helper I rankHelper I
8 years ago
Solved

Rolling data for 4 quarters

Hi,

 

Hoping the experts can help me with the dax below.

 

I have a set of data with quarter but no dates. I need to get a rolling 4 quarters ( 12 months) data for Sales and COGS.

Ie for Q1 2017 Sales = Q4 2016 QTD amt (10)+Q3 2016 QTD amt(20)+Q2 2016 QTD amt(30)+Q1 2017 QTD amt(20) =80

Q2 2017 Sales = Q3 2016 QTD amt(20)+Q4 2016 QTD amt(10)+Q1 2017 QTD amt(20)+Q2 2017 QTD amt(30) = 80

Q3 2017 Sales = Q4 2016 QTD amt(10)+Q1 2017 QTD amt(20)+Q2 2017 QTD amt(30)+Q3 2017 QTD amt(50) = 110

Q4 2017 Sales = Q1 2017 QTD amt(20)+Q2 2017 QTD amt(30)+Q3 2017 QTD amt(50)+Q4 2017 QTD amt(10) = 110

 

I have many years data as well.

 

I am trying to write a dax measure that can yield the result above for sales and COGS, can u all please help me!

 

CoAccount codeYearQuarterQTD amount
Co QSales2017120
Co QSales2017230
Co QSales2017350
Co QSales2017410
Co QSales2016140
Co QSales2016230
Co QSales2016320
Co QSales2016410
Co QCOGS201715
Co QCOGS201722
Co QCOGS201734
Co QCOGS201746
Co QCOGS201613
Co QCOGS201625
Co QCOGS201637
Co QCOGS201648
Co RSales2017118
Co RSales2017228
Co RSales2017348
Co RSales201748
Co RSales2016138
Co RSales2016228
Co RSales2016318
Co RSales201648
Co RCOGS201713
Co RCOGS201720
Co RCOGS201732
Co RCOGS201744
Co RCOGS201611
Co RCOGS201623
Co RCOGS201635
Co RCOGS201646
  • Hi,

     

    Remove Account code from the column labels.  Try this measure

     

    Rolling 4 quarter sales value = CALCULATE([Sales QTD amount],DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-9),MAX('Calendar'[Date])))

     

    Rolling 4 quarter COGS value = CALCULATE([COGS QTD amount],DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-9),MAX('Calendar'[Date])))

  • Hi,

     

    In the filter section (right hand side pane), click on Year and select Do not Summarize.

  • Hi,

     

    There is no mistake in my formula.  I think there is a problem in the Date column of your Data Table.  The 4th quarter of 2016 should be March - May of 2017, so the date should be 1 March 2017 (not 1 March 2016 - as is appearing in your PBI file).  Please check.

     

    That is all i can help with.

19 Replies

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

      Thanks Ashish! :)

       

      For this formula, we used a column data named "Data[QTD amount]". If my calculated data column is a measure instead, how should i modify the formula? Ie like i didnt have a sales/ COGS column but instead i have created a measure call Sales QTD amount using the QTD amount filtered with a category. I cant seems to find the measure to replace the Data[QTD amount] below in the formula.

       

      Rolling 4 quarter value = CALCULATE(SUM(Data[QTD amount]),DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-9),MAX('Calendar'[Date])))

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        Hi,

         

        Remove Account code from the column labels.  Try this measure

         

        Rolling 4 quarter sales value = CALCULATE([Sales QTD amount],DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-9),MAX('Calendar'[Date])))

         

        Rolling 4 quarter COGS value = CALCULATE([COGS QTD amount],DATESBETWEEN('Calendar'[Date],EDATE(MIN('Calendar'[Date]),-9),MAX('Calendar'[Date])))