Forum Discussion
Time Intelligence Functions
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
Calendar(a calculated table):
Calendar = CALENDAR(DATE(2018,1,1),DATE(2020,12,31))
There is no relationship between two tables. You may create calculated columns and meausres as below.
Calculated column:
CalendarYearMonth = YEAR('Calendar'[Date])*100+MONTH('Calendar'[Date])
YearMonth = YEAR('Table'[Transaction Date])*100+MONTH('Table'[Transaction Date])
Measure:
Current year Sales =
var tab =
SUMMARIZE(
'Table',
'Table'[Customer],
"Current Month Sales",
CALCULATE(
SUM('Table'[Amount]),
FILTER(
ALL('Table'),
'Table'[Customer]=EARLIER('Table'[Customer])&&
YEAR('Table'[Transaction Date])=YEAR(TODAY())&&
MONTH('Table'[Transaction Date])=MONTH(TODAY())
)
)
)
return
SUMX(
tab,
[Current Month Sales]
)
Prior Year Next 1 Month sales =
var tab =
SUMMARIZE(
'Table',
'Table'[Customer],
"Prior Year Next 1 month sales",
var _customer = [Customer]
return
CALCULATE(
SUM('Table'[Amount]),
FILTER(
ALL('Table'),
'Table'[Customer] = _customer&&
'Table'[YearMonth] =
CALCULATE(
MIN('Calendar'[CalendarYearMonth]),
FILTER(
ALL('Calendar'),
'Calendar'[CalendarYearMonth]>(YEAR(TODAY())-1)*100+MONTH(TODAY())
)
)
)
)
)
return
SUMX(
tab,
[Prior Year Next 1 month sales]
)
Prior Year Next 3 Month sales =
var tab =
SUMMARIZE(
'Table',
'Table'[Customer],
"Prior Year Next 3 month sales",
var _customer = [Customer]
return
CALCULATE(
SUM('Table'[Amount]),
FILTER(
ALL('Table'),
'Table'[Customer] = _customer&&
'Table'[YearMonth] in
TOPN(
3,
FILTER(
ALL('Calendar'[CalendarYearMonth]),
'Calendar'[CalendarYearMonth]>(YEAR(TODAY())-1)*100+MONTH(TODAY())
),
[CalendarYearMonth],ASC
)
)
)
)
return
SUMX(
tab,
[Prior Year Next 3 month sales]
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
v-alq-msft . Thanks for your message.
Not able to open the file that you sent. Please see the attached screenshot. I have installed multiple times but no luck.
Thanks,
Sandeep
- v-alq-msft6 years agoCommunity Support
Hi, Anonymous
I attached the pbix file with the version of 2020 July. Today is 8/4/2020. Here is the result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
Thanks for your help on this.
But the report is still showing null values in my PBI report.
Our data looks like below.
Your help and support is greatly appreciated.
Thanks,
Sandeep
- v-alq-msft6 years agoCommunity Support
Hi, Anonymous
Power BI Desktop is updated and released on a monthly basis, incorporating customer feedback and new features. Only the most recent version of Power BI Desktop is supported; customers who contact support for Power BI Desktop will be asked to upgrade to the most recent version. You can get the most recent version of Power BI Desktop from the Windows Store.
Best Regards
Allan