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.
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!
Co | Account code | Year | Quarter | QTD amount |
Co Q | Sales | 2017 | 1 | 20 |
Co Q | Sales | 2017 | 2 | 30 |
Co Q | Sales | 2017 | 3 | 50 |
Co Q | Sales | 2017 | 4 | 10 |
Co Q | Sales | 2016 | 1 | 40 |
Co Q | Sales | 2016 | 2 | 30 |
Co Q | Sales | 2016 | 3 | 20 |
Co Q | Sales | 2016 | 4 | 10 |
Co Q | COGS | 2017 | 1 | 5 |
Co Q | COGS | 2017 | 2 | 2 |
Co Q | COGS | 2017 | 3 | 4 |
Co Q | COGS | 2017 | 4 | 6 |
Co Q | COGS | 2016 | 1 | 3 |
Co Q | COGS | 2016 | 2 | 5 |
Co Q | COGS | 2016 | 3 | 7 |
Co Q | COGS | 2016 | 4 | 8 |
Co R | Sales | 2017 | 1 | 18 |
Co R | Sales | 2017 | 2 | 28 |
Co R | Sales | 2017 | 3 | 48 |
Co R | Sales | 2017 | 4 | 8 |
Co R | Sales | 2016 | 1 | 38 |
Co R | Sales | 2016 | 2 | 28 |
Co R | Sales | 2016 | 3 | 18 |
Co R | Sales | 2016 | 4 | 8 |
Co R | COGS | 2017 | 1 | 3 |
Co R | COGS | 2017 | 2 | 0 |
Co R | COGS | 2017 | 3 | 2 |
Co R | COGS | 2017 | 4 | 4 |
Co R | COGS | 2016 | 1 | 1 |
Co R | COGS | 2016 | 2 | 3 |
Co R | COGS | 2016 | 3 | 5 |
Co R | COGS | 2016 | 4 | 6 |
Solved! Go to Solution.
Hi,
You may download my PBI file from here.
Hope this helps.
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.
Hi,
You may download my PBI file from here.
Hope this helps.
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])))
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.
Hi,
The dates in Data Table are wrong. They all belong to January. Please recheck.
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.
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.
hi ashish i need your help on cash flow report
Hi.
What help?
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
Hi,
In the filter section (right hand side pane), click on Year and select Do not Summarize.
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
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?
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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |