Forum Discussion
Measure is calculated incorrectly in a table
Hi all,
I would appreciate it if someone could help me please with my measures:
I have the following table:
| Date | Item | Price |
| 01.01.2020 | A | 20 |
| 01.01.2020 | A | 25 |
| 01.01.2020 | A | 30 |
| 03.01.2020 | A | 20 |
| 10.01.2020 | A | 35 |
| 02.01.2020 | B | 50 |
| 05.01.2020 | B | 60 |
| 01.01.2020 | C | 40 |
| 01.01.2020 | C | 45 |
| 01.01.2020 | C | 50 |
| 03.01.2020 | C | 40 |
| 10.01.2020 | C | 45 |
I have calculated the percentage change for each item taking the average price for the day based on the date slicer as follows:
Percent Change =
var _max = maxx(Table,Table[Date].[Date])
var _min = MINX(Table,Table[Date].[Date])
return
(CALCULATE(AVERAGE(Table[Price]), FILTER(ALLSELECTED(Table),Table[Date].[Date]=_max))-CALCULATE(AVERAGE(Table[Price]),FILTER(ALLSELECTED(Table),Table[Date].[Date]=_min)))/CALCULATE(AVERAGE(Table[Price]),FILTER(ALLSELECTED(Price),Table[Date].[Date]=_min))*100
When I select individual items, the percentage is calculated correctly between min and max dates as follows:
But when I select all items, I get different percentage changes
Can anyone please help me to get the correct percentage changes when I select all items (the same values as when I select just one item)? I would like to present changes for all items in a table.
Thanks
dashbuilder , I created three versions of it, Please check those out in the file attached after signature
4 Replies
- amitchandak
Super User
dashbuilder , Create a separate date table and then try same formula with date table
example -
Percent Change =
var _max = maxx('DATE','DATE'[Date])
var _min = MINX('DATE','DATE'[Date])
return
(CALCULATE(AVERAGE(Table[Price]), FILTER(ALLSELECTED('DATE'),'DATE'[Date]=_max))
-CALCULATE(AVERAGE(Table[Price]),FILTER(ALLSELECTED('DATE'),'DATE'[Date]=_min)))/
CALCULATE(AVERAGE(Table[Price]),FILTER(ALLSELECTED('DATE'),'DATE'[Date]=_min))*100Also, use the divide function
- dashbuilderNew Member
amitchandak thank you for your response. I have created a new data table as follows
Then, I altered the formula as suggested:
Percent Growth = var _max = maxx('DATE','DATE'[Date]) var _min = MINX('DATE','DATE'[Date]) return DIVIDE((CALCULATE(AVERAGE(Table[Price]), FILTER(ALLSELECTED('DATE'),'DATE'[Date]=_max)) -CALCULATE(AVERAGE(Table[Price]),FILTER(ALLSELECTED('DATE'),'DATE'[Date]=_min))), CALCULATE(AVERAGE(Table[Price]),FILTER(ALLSELECTED('DATE'),'DATE'[Date]=_min)))*100Now, I get "0"s:
Am I doing something wrong? Thank you heaps.
- amitchandak
Super User
dashbuilder , I created three versions of it, Please check those out in the file attached after signature