Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Catherine84
Helper I
Helper I

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
4 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

 

You may download my PBI file from here.

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

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])))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Hi,

 

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

19 REPLIES 19
Ashish_Mathur
Super User
Super User

Hi,

 

You may download my PBI file from here.

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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])))

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])))


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks for your help Ashish. As my dates are not in calendar format, ie Q1: Jun-Aug, Q2: Sep-Nov, Q3: Dec-Feb and Q4: Mar-May.

 

I manage to build the calendar from the sample that you have shown basis the dates that i need to correspond to the above but when i pull out the rolling data using the formula, its doesnt work. Not sure if this only work on calendar basis?

 

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

 

Thanks!

You are welcome.  The formula should work ireespective of the months that fall in the year.  I will need to see yoru file with your formula.  I will make changes there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,
I have uploaded.

https://1drv.ms/u/s!AmdPdgYKa-3nb77sUTmdz_6TG_I

Hope u can access!

Hi,

 

The dates in Data Table are wrong.  They all belong to January.  Please recheck.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish

https://1drv.ms/u/s!AmdPdgYKa-3ncBrkMbDOVZa6Ia0

Updated the the date. But the rolling still not showing correctly. When I take quarter from data tab and from calendar , seems to show different data as well!

Thanks!

Hi,

 

In the First visual, i dragged year and quarter from the Calendar Table.  Also, in the slicer, drag the Year from the Calendar Table.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks Ashish! Thanks for your help!! I manage to get to it ! As my calendar [year] and the Data [Year] is different, it didnt work intitally! Really appreciate all your kind help! Has learned many things from this thread! 🙂

 

Thanks a lot !  

You are welcome.  If my reply helped, please mark my relevant post as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

hi ashish i need your help on cash flow report

Hi.

What help?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

 

Thanks for your kind reply 🙂

 

1) I tried to drag the year from the Calendar, but it doesnt come out as expected. When i tried to change the format to Date (YYY), it becomes all 1905 instead of the 2018.

2) The sum of the Q1,Q2,Q3 and Q4 sales QTD added up to 15,155,801 instead of the row under Rolling 4 quarter value under Q4

17,806,760

 

Test.PNG

Hi,

 

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks @Ashish_Mathur. That works!

 

But the rolling 4th quarter numbers is still not summing up rightly. 🙂  Expecting the numbers to be 15,155,801 instead of 17,806,760

 

 

 

Capture.PNG

Hi,

 

I cannot understand your data.  What does the Amount column in the Data Table hold.  Does that hold the figures for that quarter ot is it data till that specific quarter?  Why have you had to compute the QTD Amount column in the Data Table?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks for the reply.

The amount column holds the year to date numbers. Ie for q1 =June - Aug, q2=Aug -Nov,q3=Aug -Feb, q4=mar-may.

The QTd amount holds 3 months amount, ie q1=june -aug, q2 =sep-nov,q3=dec-feb and q4=mar-may.

I need a column that calculate rolling 4 quarters numbers. Ie if 2018 3rd quarter, I will need 2018q1+2018q2+2018q3+2017q4. For 4the quarter of 2018=2018q1+2018q2+2018q3+2018q4. 😀

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.