0
votes

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

1 Answers

1
votes

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"
    )