Forum Discussion
Measure doesn't work correctly with slicer
Hi guys,
I am trying to create a forecast for a period not ended. The measure is the next one:
Forecast = (Sales 12 last months / Sales 12 previous months * Total sales previous year) - Year-to-date sales
So, if the selected period is June 2020 the variables will be the following ones:
1. Sales 12 last months = Sales from July 2019 to June 2020
2. Sales 12 previous months = Sales from July 2018 to June 2019
3. Total sales previous year = Sales from January 2019 to December 2019
4. Year-to-date sales = Sales from January 2020 to June 2020
The problem is that when I introduce the measure on a chart and put a slicer for year 2020, the variables 'Sales 12 last months', 'Sales 12 previous months' and 'Total sales previous year' show a wrong result, because it doesn't take into account the sales from 2018 and 2019, so for example the result for 'Sales 12 previous months' is 0.
How can I solve this?
Thanks in advance.
11 Replies
- amitchandak
Super User
PwrBI01 , Use month in the slicer from the date table and try measures like
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31")) //complete
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31")) //completeLast to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
//Only year vs Year, not a level below
This Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('order'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-12,MONTH)) //last 12
// 12 before 12
Rolling 12 till last 12 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-12,month)),-12,MONTH))
Rolling 12 till last 12 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],max(dateadd(Sales[Sales Date],-12,month)),-12,MONTH))
Rolling 12 till last 12 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],max(dateadd('Date'[Date],-12,month)),-12,MONTH))To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.
- PwrBI01
Post Patron
- AnonymousNot applicable
HI PwrBI01,
Can you please share some dummy data(similar to raw table structure) and expected results to help us clarify your requirement and test coding formula?
How to Get Your Question Answered Quickly
Regards,Xiaoxin Sheng
- PwrBI01
Post Patron
Hi Anonymous,
I have share the link where you can find the file.
https://drive.google.com/file/d/1qRQ4cGYELIraQ1IzhVXeNsiCJZO46U-r/view?usp=sharing
Thanks in advance.
Regards.
- Ashish_Mathur
Super User
Hi,
In your column chart, drag Year from the Calendar Table. See the image
- Ashish_Mathur
Super User
Hi,
Share the link from where i can download your PBI file.
- PwrBI01
Post Patron
Hi Anonymous and Ashish_Mathur,
Thank you for your answers.
I send you the link where the Power BI file is located so you can download it.
https://drive.google.com/file/d/1qRQ4cGYELIraQ1IzhVXeNsiCJZO46U-r/view?usp=sharing
I have created 2 columns, one for the results I obtain when I put the measure on a target and another column for the results I get when I filter the same measures for the year 2019 (I think this are the results the chart is showing) for trying to help you to understand.
Thanks in advance.
Regards.