Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

Retrieve value same date current year

From below table, for years previous to the current year, I want to retrieve the value of WeightedDegreeDays for the same day + month but of the current year. So for the first row in this example (6 ...
  • MFelix's avatar
    9 years ago

    Hi Anonymous,

     

    You can use a column or a measure, taking into account that the column value will ocupy space in your model and the best practices for the DAX usage is to make a measure if possible and don't use calculated columns below you have the formula for the measure:

     

     

    Value_Date =
    VAR date_select =
        MIN ( GasUsagePerDegreeDay[Date] )
    RETURN
        CALCULATE (
            SUM ( GasUsagePerDegreeDay[WeightedDegreeDays] ),
            Table1[Date]
                = DATE ( YEAR ( NOW () ), MONTH ( date_select ), DAY ( date_select ) )
        )

     

    However if you want to do it in a column the formula should be this one:

     

     

    Value_Date_ =
    VAR date_lookup = Table1[Date]
    RETURN
        LOOKUPVALUE (
           GasUsagePerDegreeDay[WeightedDegreeDays],
            GasUsagePerDegreeDay[Date], DATE ( YEAR ( NOW () ), MONTH ( date_lookup ), DAY ( date_lookup ) )
        )

     

     

    Regards,

     

    MFelix