Power BI :: TOTALMTD 和 DATESMTD 返回空白。

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

Power BI :: TOTALMTD & DATESMTD are returning Blank

问题

GOAL: 财务办公室要求创建一个仪表板,他们可以在其中查看MTD(月度累计)开支。这应该很简单,对吗?

MY APPROACH: 在网上有几个指南,告诉你如何计算MTD,我的方法是这样的:

MTD = TOTALMTD(CALCULATE(SUM(Data[Cost])),DATESMTD('Calendar'[Date].[Date]))

但是当我查看结果时,我有3个问题:

  • 折线图没有显示MTD,而是取自开始以来的所有日期。
  • 折线上下波动,这没有意义。
  • 下面的卡片显示为空白。

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

我做错了什么?

您可以在这里下载:

谢谢

英文:

GOAL: the finance office is asking for a dashboard where they could check the MTD expenses. This should be easy, right?

MY APPROACH: there are several guides online that tells you how to calculate the MTD and my approach is this:

MTD = TOTALMTD(CALCULATE(SUM(Data[Cost])),DATESMTD('Calendar'[Date].[Date]))

But when I go to check the results I have 3 problems:

  • the line chart is not showing the MTD but is taking all the dates since the beginning
  • the line goes up and down and this makes no sense.
  • the card underneath is sowing blank

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

What am I doing wrong?

You can download the here the:

Thank you

答案1

得分: 2

我检查了你的日历表,最大日期是2023年7月1日:

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

而在你的数据表中,最大日期是2023年6月30日:

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

我理解如果今天是2023年7月3日,那么线图中的度量应该基于今天的默认日期和一个月前的日期返回结果:

我假设当前日期是2023年5月31日,因为你的数据没有涵盖上述区间:

MTD =
CALCULATE(
SUM(Data[成本]),
'Calendar'[日期] >= DATE(2023, 5, 31),
'Calendar'[日期] <= DATE(2023, 6, 30)
)
Power BI :: TOTALMTD 和 DATESMTD 返回空白。

如果你想让你的度量指向当前日期,在调整你的数据后,请尝试以下方法:

TotalCostMTD =
CALCULATE(
SUM(Data[成本]),
FILTER(
ALL('Calendar'[日期]),
'Calendar'[日期] <= TODAY()
)
)

更新:

我最终创建了两个度量,一个是用于当前月份,另一个是用于上个月的同期:

MTest_Current = CALCULATE(
SUM(Data[成本]),
FILTER(
Data,
Data[使用日期] >= DATE(YEAR(TODAY()), MONTH(TODAY()), 1) &&
Data[使用日期] <= TODAY()
)
)

MTest_Previous =
CALCULATE(
SUM(Data[成本]),
FILTER(
Data,
Data[使用日期] >= DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1) &&
Data[使用日期] <= DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, DAY(TODAY()))
)
)

我添加了一个日历表以遵循最佳实践:

Calendar =
ADDCOLUMNS (
CALENDARAUTO(),
"日历年", YEAR ( [日期] ),
"月份名称", FORMAT ( [日期], "mmmm" ),
"月份编号", MONTH ( [日期] ),
"日期", DAY ( [日期] ),
"季度", "Q" & TRUNC ( ( MONTH ( [日期] ) - 1 ) / 3 ) + 1
)

并且像下面这样调整了关系:

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

最终输出如OP所期望:

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

英文:

I checked your Calendar table and the maximum date is the 01st of July 2023 :

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

While in your Data table is the 30th of June 2023 :

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

I understood that if today is the the 03 rd of July 2023, the measure (in the line chart) should return the result based from today's default date and one month backward :

I assumed that the current date is 31/05/2023 since your data doesn't cover the interval mentioned above :

MTD  = 
CALCULATE(
    SUM(Data[Cost]),
    &#39;Calendar&#39;[Date] &gt;= DATE(2023, 5, 31),
    &#39;Calendar&#39;[Date] &lt;= DATE(2023, 6, 30)
)

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

If you want your measure to point on the current day, after adjusting your data try the following :

TotalCostMTD = 
CALCULATE(
    SUM(Data[Cost]),
    FILTER(
        ALL(&#39;Calendar&#39;[Date]),
        &#39;Calendar&#39;[Date] &lt;= TODAY()
    )
)

Update :

I ended up creating two measure one for the current month and the other for the same period last month :

MTest_Current = CALCULATE(
    SUM(Data[Cost]),
     FILTER(
        Data,
        Data[UsageDate] &gt;= DATE(YEAR(TODAY()), MONTH(TODAY()), 1) &amp;&amp;
        Data[UsageDate] &lt;= TODAY()
    )
)


MTest_Previous = 
CALCULATE(
    SUM(Data[Cost]),
    FILTER(
        Data,
        Data[UsageDate] &gt;= DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, 1) &amp;&amp;
        Data[UsageDate] &lt;= DATE(YEAR(TODAY()), MONTH(TODAY()) - 1, DAY(TODAY()))
    )
)

I added a calendar table to follow the best practices :

Calendar = 
ADDCOLUMNS (
    CALENDARAUTO(),
    &quot;Calendar Year&quot;, YEAR ( [Date] ),
    &quot;Month Name&quot;, FORMAT ( [Date], &quot;mmmm&quot; ),
    &quot;Month Number&quot;, MONTH ( [Date] ),
    &quot;Day&quot;, DAY ( [Date] ),
    &quot;Quarter&quot;, &quot;Q&quot; &amp; TRUNC ( ( MONTH ( [Date] ) - 1 ) / 3 ) + 1
)

And adjusted the relationships like below :

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

The final output as the OP is expecting :

Power BI :: TOTALMTD 和 DATESMTD 返回空白。

答案2

得分: 1

我使用了Ferrari & Russo用来计算累计总数的模式(稍微冗长,但您可以按照您的需求自定义它)。以下是我从您的数据集中提取的代码。

MTD 2 = CALCULATE ( 
    SUM('Data'[CostUSD] ), 
    FILTER( ALL('Calendar'), 
        'Calendar'[Date] <= MAX( 'Calendar'[Date] ) &&
        'Calendar'[Calendar Year] = MAX('Calendar'[Calendar Year]) &&
        'Calendar'[Month Number] = MAX('Calendar'[Month Number]) 
    )
)

在卡片中使用MTD度量的问题在于没有月份的评估上下文。这就是它为空的原因。简单来说,可视化无法确定应该评估哪个月份... 因为月份实际上是“空白”/不确定的,总数也为空。验证这种情况的一种方法是使用矩阵可视化,将日期放在行上,金额放在值上,然后在值上进行累计总数。如果度量工作正常,它应该加起来。

英文:

I used the pattern that Ferrari & Russo use to do running totals. (a bit more wordy, but you can customize it any way you want). Here's my code from your dataset.

    MTD 2 = CALCULATE ( 
                    SUM(&#39;Data&#39;[CostUSD] ), 
                              FILTER( ALL(&#39;Calendar&#39;), 
                                   &#39;Calendar&#39;[Date] &lt;= MAX( &#39;Calendar&#39;[Date] ) &amp;&amp;
                                   &#39;Calendar&#39;[Calendar Year] = MAX(&#39;Calendar&#39;[Calendar Year]) &amp;&amp;
                                   &#39;Calendar&#39;[Month Number] = MAX(&#39;Calendar&#39;[Month Number]) 
                              )
                )

The problem with the MTD measure in a card is that there's no evaluation context for the month. That's why it's blank. (In plainer English, there's no way for the visual to determine what month it should evaluate... and since the month is effectively "blank"/indeterminate, the total is blank too). One way to sanity check a graph like this is to use a matrix visual and put dates on rows, the Amount, and then run total on Values. It should add up if the measure is working.

huangapple
  • 本文由 发表于 2023年7月3日 21:02:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605003.html
匿名

发表评论

匿名网友

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

确定