每月最后一个日期(MAX日期)值的平均值 [英] Average of Each months last date (MAX date) value

查看:142
本文介绍了每月最后一个日期(MAX日期)值的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望计算每个月的AVG的最后日期(MAX日期)值。以下是示例数据。

I am looking to calculate AVG OF EACH Month's last date (MAX date) value. Below is the sample data.

请问有人可以帮助我进行DAX计算。非常感激。

Can you please someone help me with the DAX caluclations. Much appreciated. 

请让我知道是否需要更多信息。

Please let me know if you need more information.

Location    DATE           NAME  VALUE  
P1         1/1/2019 0:00    ABC   12    
P1  1/2/2019 0:00   ABC 4   
P1  1/3/2019 0:00   ABC 50  
P1  1/4/2019 0:00   ABC 8   
P1  1/5/2019 0:00   ABC 35  ABC MaxDate value of JAN
P1  1/1/2019 0:00   DEF 20  
P1  1/2/2019 0:00   DEF 25  
P1  1/3/2019 0:00   DEF 66  
P1  1/4/2019 0:00   DEF 24  
P1  1/5/2019 0:00   DEF 50  DEF MaxDate value of JAN
P2  2/1/2018 0:00   ABC 28  
P2  2/2/2018 0:00   ABC 82  
P2  2/3/2018 0:00   ABC 67  
P2  2/4/2018 0:00   ABC 43  
P2  2/5/2018 0:00   ABC 66  ABC MaxDate value of FEB
P2  2/1/2018 0:00   DEF 28  
P2  2/2/2018 0:00   DEF 82  
P2  2/3/2018 0:00   DEF 67  
P2  2/4/2018 0:00   DEF 43  
P2  2/5/2018 0:00   DEF 34  DEF MaxDate value of FEB

我需要的是最大日期值的平均值年初至今
ABC年初至今= AVG(35 + 66)

DEF年初至今= AVG(50 + 34)

what I need is Average of Max date values of each month as YTD ABC YTD = AVG(35+66)
DEF YTD = AVG(50+34)

我需要的是每个月的最大日期值的平均值,以YTD
ABC YTD = AVG( 35 + 66)

DEF年初至今= AVG(50 + 34)

what I need is Average of Max date values of each month as YTD ABC YTD = AVG(35+66)
DEF YTD = AVG(50+34)

推荐答案

NB:数据表,或数据是指您在问题中提供的数据表。

N.B: The Data table, or 'Data' refers to the data table you provided in the question.

方法1:

汇总这样的数据表:

SummarizedTable = 
SUMMARIZE(
    ADDCOLUMNS(
        'Data';
        "Month"; MONTH([DATE]);
        "Year"; YEAR([DATE])
    );
    [Year];
    [Month];
    [NAME];
    "MaxDateValue" = 
    var MaxD = MAX([DATE])
    return
    CALCULATE(
        SUM('Data'[VALUE]);
        'Data'[DATE] = MaxD
    )
)

您最终并带有一个新表,如下所示:

You end up with a new table looking like this:

在仪表板上,您可以使用 [NAME] SummarizedTable 中拖放> [MaxDateValue] 。在可视化窗格中的 [MaxDateValue] 上单击鼠标右键,然后选择平均值而不是和,您应该得到一个如下所示的可视表:

On your dashboard you can build a visual table with [NAME] and [MaxDateValue] by drag and drop from your new table 'SummarizedTable'. Right click on [MaxDateValue] in the visualizing pane and select average instead of sum and you should end up with a visual table looking like this:

方法2:

您可以将其转化为度量,而不必使用汇总来计算新表。这样做的好处是,您可以保留原始数据的完整性,并且可以更轻松地进行切片。

Instead of calculating a new table using summarize you can turn it into a measure. The benefit of this is that you retain the integrity of the original data and this makes it easier to slice.

AvgYtd = 
AVERAGEX(
    SUMMARIZE(
        ADDCOLUMNS(
            'Data';
            "Month"; MONTH([DATE]);
            "Year"; YEAR([DATE])
        );
        [Year];
        [Month];
        [NAME];
        "MaxDateValue" = 
        var MaxD = MAX([DATE])
        return
        CALCULATE(
            SUM('Data'[VALUE]);
            'Data'[DATE] = MaxD
        )
    );
    [MaxDateValue]
)

在仪表板上,您现在可以通过拖动 [NAME] 来创建新的可视表从原始数据表中添加新的度量值 [AvgYtd] ,这样您就有两个表显示相同的内容:

On your dashboard you can now create a new visual table by dragging [NAME] from the original Data table and then adding your new measure [AvgYtd] so that you have two tables showing the same thing:

但是,您现在可以添加切片器,例如从数据表中 [位置] 并选择P1:

However, you can now add a slicer, e.g. [Location] from the Data table and select P1:

您可以看到使用该度量创建的可视表受切片器影响,而汇总表则没有。

You can see that the visual table created using the measure is affected by the slicer, while the summarized table is not.

这篇关于每月最后一个日期(MAX日期)值的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆