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.
Hello Power BI experts!
I am trying to calculate the average price per itemCode (Product) for the previous year of each 'Date' in the Date column.
So for example, if a Product was sold on 1/1/2017, I would want to calculate the average price for this product in 2016.
I have written the following measure which returns blank values. Any ideas as to why?
The selected values statements return the expected results.
AVG Price Measure = CALCULATE ( AVERAGE( 'table'[Price] ); FILTER ( 'table'; 'table'[itemCode ] = SELECTEDVALUE ( 'table'[itemCode ) && YEAR('table'[Date]) = YEAR(SELECTEDVALUE ( 'table'[Date] ))-1 ) )Screenshot of my table:
@Anonymous have you got a date table with a list of continuous dates?
Proud to be a Super User!
Difficult to say without sample data. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
That being said, try an ALL around your 'table' in your FILTER clause and see what that does.
@Anonymous any chance you can copy and paste the date rather than screenshotting?
Proud to be a Super User!
Here is some dummy data:
Date | itemCode | Price |
3/1/2017 0:00 | 39152620 | 0,08 € |
9/1/2017 0:00 | 39152620 | 5,64 € |
30/5/2017 0:00 | 10051191 | 0,19 € |
31/5/2017 0:00 | 40353138 | 0,26 € |
1/6/2017 0:00 | 7071569 | 0,48 € |
23/4/2018 0:00 | 10041712 | 12,03 € |
24/4/2018 0:00 | 109031817 | 7,41 € |
25/4/2018 0:00 | 160023406 | 14,69 € |
26/4/2018 0:00 | 4020327 | 0,04 € |
27/4/2018 0:00 | 8040620 | 0,05 € |
30/4/2018 0:00 | 39152620 | 0,88 € |
2/5/2018 0:00 | 2010125 | 0,00 € |
Here is some dummy data:
Date | itemCode | Price |
3/1/2017 0:00 | 10051115 | 0,08 € |
9/1/2017 0:00 | 28010101 | 5,64 € |
30/5/2017 0:00 | 10051191 | 0,19 € |
31/5/2017 0:00 | 40353138 | 0,26 € |
1/6/2017 0:00 | 7071569 | 0,48 € |
2/6/2017 0:00 | 3030403 | 0,00 € |
6/6/2017 0:00 | 6011486 | 11,06 € |
7/6/2017 0:00 | 4040592 | 6,48 € |
9/6/2017 0:00 | 1010121 | 0,02 € |
12/6/2017 0:00 | 1010266 | 0,06 € |
22/6/2017 0:00 | 4020548 | 0,01 € |
23/6/2017 0:00 | 1010127 | 35 € |
27/7/2017 0:00 | 8061240 | 4,23 € |
28/7/2017 0:00 | 3020492 | 0,20 € |
17/11/2017 0:00 | 15110661 | 0,15 € |
21/11/2017 0:00 | 7040828 | 1,60 € |
22/11/2017 0:00 | 17101678 | 100,02 € |
23/11/2017 0:00 | 2010213 | 0,00 € |
27/11/2017 0:00 | 87143587 | 22,08 € |
28/11/2017 0:00 | 47333115 | 0,65 € |
29/11/2017 0:00 | 28020201 | 2,30 € |
30/11/2017 0:00 | 35102844 | 3,01 € |
4/12/2017 0:00 | 12151126 | 2,97 € |
5/12/2017 0:00 | 2010125 | 0,00 € |
6/12/2017 0:00 | 8040578 | 0,05 € |
7/12/2017 0:00 | 11121437 | 0,04 € |
8/12/2017 0:00 | 4030825 | 0,10 € |
11/12/2017 0:00 | 7001253 | 6,26 € |
12/12/2017 0:00 | 6080565 | 0,02 € |
13/12/2017 0:00 | 37041739 | 13,56 € |
31/1/2018 0:00 | 14071223 | 2,91 € |
7/2/2018 0:00 | 4020296 | 0,03 € |
9/2/2018 0:00 | 5110293 | 0,01 € |
12/2/2018 0:00 | 6040759 | 0,34 € |
16/4/2018 0:00 | 3040303 | 0,01 € |
17/4/2018 0:00 | 2010140 | 0,00 € |
19/4/2018 0:00 | 3991001 | 5,50 € |
20/4/2018 0:00 | 60105442 | 17,43 € |
23/4/2018 0:00 | 10041712 | 12,03 € |
24/4/2018 0:00 | 109031817 | 7,41 € |
25/4/2018 0:00 | 160023406 | 14,69 € |
26/4/2018 0:00 | 4020327 | 0,04 € |
27/4/2018 0:00 | 8040620 | 0,05 € |
30/4/2018 0:00 | 39152620 | 0,88 € |
2/5/2018 0:00 | 2010125 | 0,00 € |
@Anonymous your screenshot didn't show up
Proud to be a Super User!
Fixed, sorry!
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 |
---|---|
112 | |
100 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
111 | |
92 | |
84 | |
66 |