Forum Discussion
Strange behaviour with SAMEPERIODLASTYEAR
Hi,
I'm building a Power BI report which is analysing PoS transaction data so have a fact table (Transactions) with every individual transaction including timestamp and sales amount (Transactions[Sales]).
I've added a custom column for the transaction date (Transactions[Date]) which is joined to a calendar table (Calendar) which is generated from MIN(Transactions[Date]) to MAX(Transactions[Date]).
I've created measures for
Total Sales = SUM(Transactions[Sales]
Total Sales Last Year = CALCULATE([Total Sales],SAMEPERIODLASTYEAR('Calendar'[Date]))
The problem occurs when I include the last date in the Calendar table when calculating Total Sales Last Year.
As you can see below, if I select 13 - 14 July 2019 the calculations are correct i.e. the Total Sales Last Year are for the corresponding 2 days in 2018.
Note the the Date slider is Calendar[Date] and the Date column in the table is Transactions[Date].
If I change this to be 14 - 15 July 2019 where 15 July is the last date for any transactions, the Total Sales Last Year is incorrectly calculated for the period 14 - 30 July.
I have found a workaround which involves adding some additional days to the end of my Calendar table but the problem will occur again if these future days are selected in my date filter.
Am I using this function incorrectly or is there a bug?
Thanks,
Michael
Hi michaelstone ,
Sorry for my mistake.
Please modify the measure Total Sales - Previous Year like below.
Total Sales - Previous Year = SUMX ( 'Calendar', CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Calendar'[Date] ) ) )Here is the output.
Best Regards,
Cherry
8 Replies
- v-piga-msft
Resident Rockstar
Hi michaelstone ,
Based on your information, I have made a test with your formula, I cannot reproduce your issue.
If it is convenient, could you share your data sample and so that we could help further on it?
You also could have a test on my test sample which has been attached below.
Best Regards,
Cherry
- michaelstone
Helper I
Hi v-piga-msft ,
Here is a link to a file which shows the issue.
Note that the end date is now 17 July so you need to have this as the end date to see the issue.
Thanks,
Michael
- v-piga-msft
Resident Rockstar
Hi michaelstone ,
By my test and research based on your pbix, I'm afraid that you should create the table with the date column from Calendar table like below so that you could get the correct output.
Best Regards,
Cherry