Forum Discussion
How to calculate sameperiodlastyear ?
Dear all,
I have a table that I want to calculate sameperiodlastyear value, but since there are multi sameperiods in time column, the dax returns blank. My formula is like: Value_sameperiodlastyear = CALCULATE(sum[value],SAMEPERIODLASTYEAR([monthyear])).
My table example is as following:
| monthyear | customer | Value | Value_sameperiodlastyear |
| 1/1/2017 | A | 1111 | 111 |
| 1/1/2017 | B | 2222 | 222 |
| 1/1/2017 | C | 3333 | 333 |
| 1/1/2016 | A | 111 | |
| 1/1/2016 | B | 222 | |
| 1/1/2016 | C | 333 |
Column "Value_sameperiodlastyear" is the result I want, by using the first three columns.
Do you guys know how to write the correct formula? Many thanks!
If you use the same formula as a MEASURE it will work
Probably you are using it as Calculated Column
= CALCULATE(sum(TableName[Value]),SAMEPERIODLASTYEAR(TableName[monthyear]))
If you have to use a Calculated Column use this
Column = CALCULATE ( SUM ( TableName[Value] ), ALLEXCEPT ( TableName, TableName[customer] ), SAMEPERIODLASTYEAR ( TableName[monthyear] ) )
1 Reply
- Zubair_Muhammad
Community Champion
If you use the same formula as a MEASURE it will work
Probably you are using it as Calculated Column
= CALCULATE(sum(TableName[Value]),SAMEPERIODLASTYEAR(TableName[monthyear]))
If you have to use a Calculated Column use this
Column = CALCULATE ( SUM ( TableName[Value] ), ALLEXCEPT ( TableName, TableName[customer] ), SAMEPERIODLASTYEAR ( TableName[monthyear] ) )