DAX 在度量值中引用前一行。

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

DAX Refer to previous row within a measure

问题

根据您提供的信息,您需要计算一个队列(Queue)的值,该队列的计算方式如下:

  1. SELECTEDVALUE ( ****前一行队列值**** ) + SELECTEDVALUE ( Feuil3[Input] ) - SELECTEDVALUE ( Feuil3[Output] )

要解决循环依赖错误,您可以尝试以下方法:

  1. VAR activseq = SELECTEDVALUE ( Feuil3[Sequence] )
  2. VAR prevseq = activseq - 1
  3. VAR prevQueue =
  4. CALCULATE(
  5. SELECTEDVALUE(Feuil3[Queue]),
  6. FILTER(ALL(Feuil3), Feuil3[Sequence] = prevseq)
  7. )
  8. VAR result =
  9. IF (
  10. SELECTEDVALUE ( Feuil3[Input] ) > SELECTEDVALUE ( Feuil3[Output] ),
  11. prevQueue + SELECTEDVALUE ( Feuil3[Input] ) - SELECTEDVALUE ( Feuil3[Output] ),
  12. 0
  13. )
  14. RETURN
  15. result

这个公式首先计算前一行的队列值(prevQueue),然后使用您提供的公式计算新的队列值。

请确保将此公式应用于您的数据模型中,并相应地替换Feuil3[Queue]、Feuil3[Input]和Feuil3[Output],以匹配您的数据表和列名。

英文:

Given the data below where Queue2 represent the difference between the Input and Output if the input is greater than the output:

DAX 在度量值中引用前一行。

And the following measure to determine the amount of items in the queue:

  1. queue =
  2. VAR activseq =
  3. SELECTEDVALUE ( Feuil3[Sequence] )
  4. VAR prevseq = activseq - 1
  5. VAR preval =
  6. LOOKUPVALUE ( Feuil3[Queue2], Feuil3[Sequence], prevseq )
  7. VAR calc =
  8. MAX ( Feuil3[Input] ) - MAX ( Feuil3[Ouput] )
  9. VAR result =
  10. IF (
  11. SELECTEDVALUE ( Feuil3[Input] ) > SELECTEDVALUE ( Feuil3[Ouput] ),
  12. SELECTEDVALUE ( Feuil3[Input] ) + preval
  13. - SELECTEDVALUE ( Feuil3[Ouput] ),
  14. 0
  15. )
  16. RETURN
  17. result

I get the following result:

DAX 在度量值中引用前一行。

However, I need to achieve the following result:

Sequence Input Output Queue
1 9 50 0
2 51 50 1
3 120 50 71
4 41 50 62
5 50 50 62
6 51 50 63
7 52 50 65

To achieve this result, I need the following formula:

  1. SELECTEDVALUE ( ****Previous row Queue value**** ) + SELECTEDVALUE ( Feuil3[Input] ) - SELECTEDVALUE ( Feuil3[Ouput] )

I have tried but I encounter a circular dependency error:

  1. VAR prevHourQueue =
  2. CALCULATE(
  3. [queue],
  4. FILTER(ALL('Hour Chart'), 'Hour Chart'[Hour #] = prevseq)
  5. )

How can this be achieved?

答案1

得分: 2

以下是翻译好的内容:

要么我做错了什么,要么你的数字不符合。这是我计算的超出输入(超过50)的累计总和:

  1. RT 超出输入 = CALCULATE([超出输入],
  2. FILTER(
  3. ALL('表格'),
  4. [顺序] <= MAX('表格'[顺序])
  5. )
  6. )

超出输入只是这样的:

  1. 超出输入 = SUMX('表格',
  2. IF([顺序]=1,0,[输入]-[输出])

)

(只忽略表格中的第一行),否则计算差异。我的结果是{0,1,71,62,62,63,65}。

英文:

Either I'm doing something wrong, or your numbers don't add up. This is my running total for excess input (above 50)

  1. RT Excess Input = CALCULATE([Excess Input],
  2. FILTER(
  3. ALL(&#39;Table&#39;),
  4. [Sequence]&lt;=MAX(&#39;Table&#39;[Sequence])
  5. )
  6. )

Excess Input is just this:

  1. Excess Input = SUMX(&#39;Table&#39;,
  2. IF([Sequence]=1,0,[Input]-[Output])

)

(Just ignores the first row in the table), otherwise calculates the difference. My result goes {0,1,71,62,62,63,65}

huangapple
  • 本文由 发表于 2023年8月5日 01:09:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837942.html
匿名

发表评论

匿名网友

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

确定