Search code examples
powerbidaxpowerbi-desktopmeasure

Get first value of year with dax


I have the following table

Value
1/1/2023 53
1/1/2023 54
1/1/2023 52
1/2/2023 55
1/2/2023 51
1/2/2023 52
1/2/2023 60
1/3/2023 41
1/3/2023 44

I created a dax formula which gives me the first value of 1/1/2023:

CALCULATE(
    FIRSTNONBLANK('Turn Over'[Effectif avant],'Turn Over'[Effectif avant]),
    MONTH('Turn Over'[Date])=1
)

The problem with this is that once I am in 2024 it will still take the first non blank value of 2023.

How can I overcome this issue?


Solution

  • CALCULATE(
        FIRSTNONBLANK('Turn Over'[Effectif avant],'Turn Over'[Effectif avant]),
        MONTH('Turn Over'[Date])=1 && YEAR('Turn Over'[Date])=2024
    )
    

    or dynamic:

    CALCULATE(
        FIRSTNONBLANK('Turn Over'[Effectif avant],'Turn Over'[Effectif avant]),
        MONTH('Turn Over'[Date])=1 && YEAR('Turn Over'[Date])=YEAR(TODAY())
    )