Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have formula for YTD which is working perfectly. Prior YTD formula only works fine if I have values for current year but if none, the result is blank.
Calculations I used:
YTD Sales =
SWITCH(
TRUE(),
[Max Year]=2019,
TOTALYTD([Actual Sales],'Metric Date'[Date])
)
Prior YTD Sales =
SWITCH(
TRUE(),
[Max Year]=2019,
CALCULATE([Actual Sales],PARALLELPERIOD('Metric Date'[Date],-12,MONTH)),
BLANK()
)
Result:
If there are values for YTD then the output for Prior YTD is also correct but if YTD is blank, then the output becomes blank also but it should contain a value.
This should be the correct result:
I had a temporary solution for Prior YTD if there's no value for YTD. I only have 2 years worth of data in my data source. My temp solution does not work if I use the month slicer because my formula is already set to use Jan to previous month eg. May so in my Month slicer if I select Jan-April, my chart still shows data from Jan-May.
Prior YTD Actual =
SWITCH(
TRUE(),
[Max Year]=2019,
CALCULATE([Actual Expense],PARALLELPERIOD('Metric Date'[Date],-12,MONTH)),
[Max Year]=2018,
CALCULATE([Actual Expense],DATESBETWEEN('Metric Date'[Date],DATE(2018,1,1),DATE(2018,5,1))),
BLANK()
)
Is there anyone who can help me on this?
First of all, you should check if your model has a proper DATE TABLE that covers all full years for which there is at least one date in any one of your tables. You have to specifically designate the table as DATE TABLE. Then and only then will date intelligence functions work as expected.
Yes my Metric Date table is marked as Date Table
Please make a screenshot of your whole model and paste.
Stachu's formulas are correct and if the model is set up correctly, they will work OK out of necessity. Looks like your model is flawed.
Best
Darek
first of all you need to decide on what's the point of reference for the time in your model - I suggest using the slicer
assuming the your Actuals Sales measures looks something like this:
Actual Sales = SUM(Table[Sales])
let's consider a scenario where you selected May 2019 (not Jan-May 2019, just May 2019)
these measure should work fine for you then:
YTD Sales = CALCULATE([Actual Sales], DATESYTD('Metric Date'[Date]))
PY YTD Sales = CALCULATE([YTD Sales], SAMEPERIODLASTYEAR('Metric Date'[Date]))
with these measures the YTD will be calculated in reference to your filter context (e.g. slicer)
Hi Stachu,
In my case, your formula only works if there's data for current year (2019) so the PY returns correct output however, if there's no data for current year, it does not calculate correctly and returns blank.
User | Count |
---|---|
25 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
27 | |
13 | |
13 | |
11 | |
6 |