Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

Average of Selected Value returns blank values

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:
img1.JPG
7 REPLIES 7
vanessafvg
Super User
Super User

@Anonymous have you got a date table with a list of continuous dates?

 

AVG Price Measure Last year =
CALCULATE (
AVERAGE(PreviousValue[Price]),
SAMEPERIODLASTYEAR('Calendar'[Date]))
 
try this but you need a date table
 
easy to create, in the modelling on the visual pain see new table and paste Calendar = calendarauto(), then create a many to one single relationship from your transactional table to your date table on date.
 
the above should work then, it will obviously only return was existed the previous year




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Greg_Deckler
Super User
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. 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
vanessafvg
Super User
Super User

@Anonymous  any chance you can copy and paste the date rather than screenshotting? 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

Here is some dummy data: 

 

DateitemCodePrice
3/1/2017 0:00391526200,08 €
9/1/2017 0:00391526205,64 €
30/5/2017 0:00100511910,19 €
31/5/2017 0:00403531380,26 €
1/6/2017 0:0070715690,48 €
23/4/2018 0:001004171212,03 €
24/4/2018 0:001090318177,41 €
25/4/2018 0:0016002340614,69 €
26/4/2018 0:0040203270,04 €
27/4/2018 0:0080406200,05 €
30/4/2018 0:00391526200,88 €
2/5/2018 0:0020101250,00 €
Anonymous
Not applicable

Here is some dummy data:

 

DateitemCodePrice
3/1/2017 0:00100511150,08 €
9/1/2017 0:00280101015,64 €
30/5/2017 0:00100511910,19 €
31/5/2017 0:00403531380,26 €
1/6/2017 0:0070715690,48 €
2/6/2017 0:0030304030,00 €
6/6/2017 0:00601148611,06 €
7/6/2017 0:0040405926,48 €
9/6/2017 0:0010101210,02 €
12/6/2017 0:0010102660,06 €
22/6/2017 0:0040205480,01 €
23/6/2017 0:00101012735 €
27/7/2017 0:0080612404,23 €
28/7/2017 0:0030204920,20 €
17/11/2017 0:00151106610,15 €
21/11/2017 0:0070408281,60 €
22/11/2017 0:0017101678100,02 €
23/11/2017 0:0020102130,00 €
27/11/2017 0:008714358722,08 €
28/11/2017 0:00473331150,65 €
29/11/2017 0:00280202012,30 €
30/11/2017 0:00351028443,01 €
4/12/2017 0:00121511262,97 €
5/12/2017 0:0020101250,00 €
6/12/2017 0:0080405780,05 €
7/12/2017 0:00111214370,04 €
8/12/2017 0:0040308250,10 €
11/12/2017 0:0070012536,26 €
12/12/2017 0:0060805650,02 €
13/12/2017 0:003704173913,56 €
31/1/2018 0:00140712232,91 €
7/2/2018 0:0040202960,03 €
9/2/2018 0:0051102930,01 €
12/2/2018 0:0060407590,34 €
16/4/2018 0:0030403030,01 €
17/4/2018 0:0020101400,00 €
19/4/2018 0:0039910015,50 €
20/4/2018 0:006010544217,43 €
23/4/2018 0:001004171212,03 €
24/4/2018 0:001090318177,41 €
25/4/2018 0:0016002340614,69 €
26/4/2018 0:0040203270,04 €
27/4/2018 0:0080406200,05 €
30/4/2018 0:00391526200,88 €
2/5/2018 0:0020101250,00 €
vanessafvg
Super User
Super User

@Anonymous  your screenshot didn't show up





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

Fixed, sorry!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.