Power BI DAX summarize and filter by date

﹥>﹥吖頭↗ 提交于 2021-01-29 16:32:08

问题


I have a Power BI report and I want to find the last date some action took place that had a non-0 value. In the following example:

|-------------|------------|
|  ActionDate |   ActionAmt|
|-------------|------------|
| 1-Feb       |  -100      |
|-------------|------------|
| 1-Feb       |   100      |
|-------------|------------|
| 10-Jan      |   150      |
|-------------|------------|

I want to return the 10-Jan date, not 1-Feb, since 10-Jan is the first non-0 value summed by ActionDay. My code returns 1-Feb:

Last Action Date =
VAR maxdatekey =
    CALCULATE ( MAX ( 'Action'[ActionDateKey] ), 'Action'[ActionAmount] > 0 )
RETURN
    IF (
        maxdatekey,
        FORMAT (
            LOOKUPVALUE ( 'Date'[DateValue], 'Date'[DateKey], maxdatekey ),
            "dd-MMM-yyyy"
        )
    )

How do I further group this to exclude the summarized 0 days?


回答1:


I think you're looking for something like this where you summarize by date when calculating the amount:

LastActionDate =
VAR Summary =
    SUMMARIZE (
        'Date',
        'Date'[DateValue],
        "Amt", CALCULATE ( SUM ( 'Action'[ActionAmount] ) )
    )
RETURN
    FORMAT (
        MAXX ( FILTER ( Summary, [Amt] > 0 ), 'Date'[DateValue] ),
        "dd-MM-yyyy"
    )


来源:https://stackoverflow.com/questions/62420180/power-bi-dax-summarize-and-filter-by-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!