Power Pivot – 获取上一年的总和

huangapple go评论65阅读模式
英文:

Power Pivot - Get previous Year sum

问题

我有一个包含以下列标题的表格:

DeptName - ActualFees - Month - Year

我想在聊天中根据一个切片器选择年份(包括前一年),显示DeptName和金额。我尝试了几个代码,但都没有成功。年份列不是日期格式。

我已经尝试过:

SUMX (Table, Table[Year]=Table[Year]-1)

Calculate( Sum(Table[ActualFee], Table[Year]=Table[Year]-1)

SUMX( Filter(Table,
      Table[Year] = Table[Year]-1,
      Table[ActualFees])
英文:

I have a table with these headers:

DeptName - ActualFees - Month - Year

I want to see in a chat the Deptname and the amount, according to a slicer to select the year, plus the previous year. I have tried a few codes but none worked. The Year column is not in a date format.

I already tried:

SUMX (Table, Table[Year]=Table[Year]-1

Calculate( Sum(Table[ActualFee], Table[Year]=Table[Year]-1)

SUMX( Filter(Table,
      Table[Year] = Table[Year]-1,
      Table[ActualFees])

答案1

得分: 1

你可以使用类似以下的代码:

=VAR thisYear = VALUES(Table1[Year])
RETURN
IF(HASONEVALUE(Table1[Year]),CALCULATE(SUM([ActualFees]),ALL(Table1[YEAR]),Table1[Year]=thisYear-1),blank())
英文:

You could use something like:

=VAR thisYear = VALUES(Table1[Year])
RETURN
IF(HASONEVALUE(Table1[Year]),CALCULATE(SUM([ActualFees]),ALL(Table1[YEAR]),Table1[Year]=thisYear-1),blank())

huangapple
  • 本文由 发表于 2023年7月27日 18:15:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76778727.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定