The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi, this is my first post so please forgive me if this has been answered elsewhere (I did search before posting, honest).
I have a pricing file where I collect and compare various sources of prices for products. I'm then comparing the price last calendar week (w-1) to the week prior (w-2). I created a Date hierarchy to help with this. Here is my formula:
@Anonymous
try
WoW $ =
var _prevWeek = DATEADD('Date'[Date],-1, WEEK)
var _prev2Week = DATEADD(_prevWeek,-1, WEEK)
RETURN
CALCULATE (
AVERAGE ( 'Main_Data_Feed'[Price Point] ),
FILTER (
ALL ( 'Date' ),
YEAR('Date'[Date]) = YEAR(_prevWeek) && MONTH('Date'[Date]) = MONTH(_prevWeek)
)
)
- CALCULATE (
AVERAGE ( 'Main_Data_Feed'[Price Point] ),
FILTER (
ALL ( 'Date' ),
YEAR('Date'[Date]) = YEAR(_prev2Week) && MONTH('Date'[Date]) = MONTH(_prev2Week)
)
)
do not hesitate to give a kudo to useful posts and mark solutions as solution
Thanks for this but this returns an error:
'The last argument must be one of these keywords: DAY, MONTH, QUARTER, or YEAR.'
And refers to WEEK in lines 2 and 3
@Anonymous
no problem, sorry, didnt check
WoW $ =
var _prevWeek = DATEADD('Date'[Date],-7, DAY)
var _prev2Week = DATEADD(_prevWeek,-7, DAY)
RETURN
CALCULATE (
AVERAGE ( 'Main_Data_Feed'[Price Point] ),
FILTER (
ALL ( 'Date' ),
YEAR('Date'[Date]) = YEAR(_prevWeek) && MONTH('Date'[Date]) = MONTH(_prevWeek)
)
)
- CALCULATE (
AVERAGE ( 'Main_Data_Feed'[Price Point] ),
FILTER (
ALL ( 'Date' ),
YEAR('Date'[Date]) = YEAR(_prev2Week) && MONTH('Date'[Date]) = MONTH(_prev2Week)
)
)
do not hesitate to give a kudo to useful posts and mark solutions as solution
When I add that to the visual I get another error. Any ideas?
@Anonymous
try this or give us data model and data example please
WoW $ =
var _prevWeek = DATEADD(SELECTEDVALUE('Date'[Date]),-7, DAY)
var _prev2Week = DATEADD(_prevWeek,-7, DAY)
RETURN
CALCULATE (
AVERAGE ( 'Main_Data_Feed'[Price Point] ),
FILTER (
ALL ( 'Date' ),
YEAR('Date'[Date]) = YEAR(_prevWeek) && MONTH('Date'[Date]) = MONTH(_prevWeek)
)
)
- CALCULATE (
AVERAGE ( 'Main_Data_Feed'[Price Point] ),
FILTER (
ALL ( 'Date' ),
YEAR('Date'[Date]) = YEAR(_prev2Week) && MONTH('Date'[Date]) = MONTH(_prev2Week)
)
)
do not hesitate to give a kudo to useful posts and mark solutions as solution
Hi @Anonymous
how is look like your 'Date'[Week] ?
give as data example for this column please
do not hesitate to give a kudo to useful posts and mark solutions as solution
Week = WEEKNUM('Date'[Date])
User | Count |
---|---|
25 | |
10 | |
8 | |
6 | |
6 |
User | Count |
---|---|
31 | |
12 | |
10 | |
10 | |
9 |