Forum Discussion

Nicpet0's avatar
Nicpet0
Frequent Visitor
1 year ago
Solved

Comparing values with the same date range

Hi Community I would like to get some help with a DAX measure. I want to have a bar chart like shown in the snippet, where i compare values from previous years, but my struggle is to have the same...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Nicpet0 

     

    Here's my solution, hope it helps!

    1. Create a calculated column in the calendar table that marks whether each date falls within the same date range for the current year.

     

    IsInCurrentYearRange = 
    VAR CurrentYear = YEAR(MAX('Table'[Date]))
    VAR CurrentMonth = MONTH(MAX('Table'[Date]))
    VAR MaxCurrentDate = DAY(MAX('Table'[Date]))
    RETURN 
    IF(
        'Calendar'[Year] < CurrentYear &&
        'Calendar'[Month] == CurrentMonth &&
        'Calendar'[Day] > MaxCurrentDate,
        0,
        1
    )

     

    2. Create a measure to calculate revenue in the same date range.

     

    SameDateRangeRevenue = 
    CALCULATE(
        SUM('Table'[Value]),
        FILTER(
            'Calendar',
            'Calendar'[IsInCurrentYearRange] = 1
        )
    )

     

    3. Here is final result.

     

    Best Regards,
    Jarvis Tang
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.