Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
I'm trying out some DAX functions on the following data:
I
I've set up this measure
Sales YTD = Calculate(TOTALYTD(SUM(Sales[Sale£]),Sales[OrderDate]))
and used it in the following table
Now I'd like to add in sales for the previous year, so I've created a new measure using DATEADD:
Sales LY = Calculate(SUM(Sales[Sale£]),DATEADD(Sales[OrderDate],-1,YEAR))
But when I try to add this to the above table, I get:
This doentn't make much sense to be. What does it mean that "the date column is not unique" - does it expect unique date values? In the context of my example, this is nonsense as there are many orders on some days and none on many other days!
Please help!!
Solved! Go to Solution.
Are you using the Date from the Date table in the visualisation?
In the measure, yes, but not in the Table, where I use "Order Date", from the Sales table:::
Sales SPLY = Calculate([Total Sales],SAMEPERIODLASTYEAR('Date Table'[Date]))
So I've tried using the Date from "Dates Table" and it seems to work:
I'm not entirely sure why one way works and another doesn't, I need to mug up on DAX date processing
I had a very similar problem, but was able to solve it using this person's solution:
Defanging the “contiguous date selections” error - P3 Adaptive
Basically I incorporated an If(hasonevalue segment in the formula.
This is the best solution I would say, no need to create date table.
Time intelligence works best when you have a Date table.
Depending on your data, DATEADD won't play nicely if you don't use a Date table. That's what the message is all about.
In the visualisation that is complaining about the Sales LY measure, there isn't really a concept of current year and last year because there is no date field in the table.
You can see in the other visualisation that has 'Sales LY', and doesn't complain, that the results are patchy as there isn't equivalent data from the day a year previous for many of the rows.
Thnks for this HotChilli.
I'm now trying to set up a Dates table, but am getting weird results at the first step - as you wan see from the amage below, I'm aiming to set up a dates table for all days between 2010 and 2035 but Power BI in starting my table on 23/6/1906(!) and ending it on 16/016/1937 (!!)
Any ideas?
Thanks!
Just worked out the answer to this, I've got the parameters in the wrong order.
Duh!!
OK, now I've created a Dates Table and related it for the "Order Date" on the "Sales" table.
I've also created a new Measure:
Sales SPLY = Calculate([Total Sales],SAMEPERIODLASTYEAR('Date Table'[Date]))
But when I use this measure in a simple Order date: Total sales table, it seems to ignore the SAMEPERIODLASTYEAR parameter - "Total" Sales always equals "Sales SPLY"
PBI Desktop Doc is at https://1drv.ms/u/s!AmxJyApgEAcYgtUoRdtcWBWIJcYTrQ
Any ideas?
Are you using the Date from the Date table in the visualisation?
In the measure, yes, but not in the Table, where I use "Order Date", from the Sales table:::
Sales SPLY = Calculate([Total Sales],SAMEPERIODLASTYEAR('Date Table'[Date]))
So I've tried using the Date from "Dates Table" and it seems to work:
I'm not entirely sure why one way works and another doesn't, I need to mug up on DAX date processing
Source data is at https://1drv.ms/x/s!AmxJyApgEAcYgtUghDmk57MBicCw0A
Desktop is at https://1drv.ms/u/s!AmxJyApgEAcYgtUjeBKUTlHNCDxE_w
User | Count |
---|---|
60 | |
22 | |
18 | |
18 | |
16 |
User | Count |
---|---|
86 | |
54 | |
54 | |
38 | |
21 |