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
Kaizu80
Frequent Visitor

Needing a measure for last sales price

Hi!

 

I want to make a price variance index to our Sales team. The data looks like this (Date-Code-Price):

InvoiceDateItemCodeUnitPrice  
2.12.20161699150  Last price
31.1.20161948151,82  
29.2.20161948139,98  
31.3.20161948128,07  
30.4.20161948162,51  
31.5.20161948208,29  
30.6.20161948240,73  
31.7.20161948178,91  
31.8.20161948168,04  
30.9.20161948170,03  
30.11.20161948170,03  
31.1.20171948234,05 Last price
31.1.20161949137,58  
29.2.20161949126,85  
31.3.20161949116,07  
30.4.20161949147,28  
31.5.20161949188,76  
30.6.20161949218,16  
31.7.20161949162,14  
31.8.20161949152,29  
30.9.20161949154,09  
31.10.20161949147,66  
30.11.20161949154,09  
31.12.20161949195,47  
31.1.20171949212,1  
28.2.20171949210,01  
31.3.20171949192,65  
30.4.20171949214,7  
31.5.20171949201,89  
1.6.20171949201,89  
1.6.20171949194,93  
30.6.20171949188,8  
31.7.20171949189,76  Last price
29.4.20161995-380,4  
27.5.20161995150  
17.6.20161995120  
29.6.2016199550  
18.8.2016199550  
31.8.2016199550  
16.9.20161995150  Last price
15.2.20161999345  
31.3.20161999-4171,5  
15.6.20161999-1217,24  
16.6.20161999-150  
23.8.20161999-150  
18.11.20161999-800  
22.12.20161999-3100  
20.4.2017199911,9  
16.6.20171999523  Last price

 

How do I make a Measure or edit the data in the query editor so that I would be able to pick the latest sales price per item from the whole data? I do not want to delete anything since I want to compare the latest price to our average price.

 

BR

Kaj

1 ACCEPTED SOLUTION
v-sihou-msft
Employee
Employee

@Kaizu80

 

You can create measure like below:

 

Last Price = 
var maxDate=CALCULATE(MAX(Table2[Date]),ALLEXCEPT(Table2,Table2[Item]))
return
CALCULATE(SUM(Table2[Price]),FILTER(Table2,Table2[Date]=maxDate))

444.PNG

 

Regards,

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi,

How would measure be modified to include last price based on customers and not just product code? I have multiple customers who buy the same product code and would like to be able to see last price for each customer for each product item.

 

Anonymous
Not applicable

I have a very similar dataset but I'm getting the following error:

 

"A single value for variaton 'Date' for column 'Date' in table 'GRVTrans' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

v-sihou-msft
Employee
Employee

@Kaizu80

 

You can create measure like below:

 

Last Price = 
var maxDate=CALCULATE(MAX(Table2[Date]),ALLEXCEPT(Table2,Table2[Item]))
return
CALCULATE(SUM(Table2[Price]),FILTER(Table2,Table2[Date]=maxDate))

444.PNG

 

Regards,

 

@v-sihou-msft Thank you! This works good! Although I had to change the Price calculation from Sum to Average due to our not so accurate data 🙂

 

Joschko
Helper I
Helper I

Hi,

create a column sequence:

 

 

Sequence = VAR InvDate = Sales[InvoiceDate]

RETURN

COUNTROWS(Filter(CALCULATETABLE(Sales;ALLEXCEPT(Sales;Sales[ItemCode]));Sales[InvoiceDate]>=InvDate))

 

You will get a 1 for the latest entry per ItemCode. A 2 for the second latest entry,.. and so on.

 

HTH

Jörg

 

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.