I want to move some calculation from Powerbi to SQL so only the results will be in Powerbi
Powerbi code:
MoM =
IF(
ISFILTERED('X'[Year-month]),
VAR __PREV_MONTH =
CALCULATE(
SUM('X'[stock_value_current]),
DATEADD('X'[Year-month].[Date], -1, MONTH)
)
RETURN
CALCULATE(SUM('X'[stock_value_current])-__PREV_MONTH)
)
Assuming this is a headline figure, and that [year-month] is a date column:
select sum(t1.stock_value_current) - sum(t2.stock_value_current)
from MyTable t1
left join MyTable t2
on t2.[year-month] = dateadd(mm,-1,t1.[year-month])
where t1.[year-month] = @MyDateParameter
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.