Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

measure value incorrect when no data present

Hi, I'm developing a report and i have data starting from 2017.Q2 only to current Quarter 2019Q2. I have a table visual with "Total Sales", and "ThreeyearAverage Total Sales" with below measures for...
  • sturlaws's avatar
    7 years ago

    Hi Anonymous,

     

    I have had a look at your code, and you need to rewrite it a little to get what you are looking for. The code you posted:

    3 Year Sales =
    CALCULATE (
        SUM ( SalesAgg[Sales] ) + 0,
        FILTER (
            ALL ( 'DATES' ),
            AND (
                'DATES'[Year]
                    >= SELECTEDVALUE ( 'DATES'[Year] ) - 2,
                'DATES'[Quarter] = SELECTEDVALUE ( 'DATES'[Quarter] )
            )
        )
    )

    calculates, according to the conditions of the FILTER-function that you should sum all values where year is greater than or equal to the year in the current filter context - 2. When you look at the first row of your table, your earliest period is Q2 2017. This means that your code is summing all rows where year greater than or eqaul to 2015.

    You also have a condition which says you should only sum rows where the quarter number is the same as the current quarter number. Not sure whether this is intentional or not. So again, looking at your first reporting period Q2 2017, the [3 year sale] is the sum of all Q2 where year is greater than 2015.

    I am not entirely sure what you are trying to do, so I can only make an educated guess as to what your measure should look like:

    3 Year Sales =
    CALCULATE (
        SUM ( SalesAgg[Sales] ) + 0,
        FILTER (
            ALL ( 'DATES' ),
            'DATES'[Year]
                >= SELECTEDVALUE ( 'DATES'[Year] ) - 2
                && 'DATES'[Year] <= SELECTEDVALUE ( 'DATES'[Year] )
                && 'DATES'[Quarter] = SELECTEDVALUE ( 'DATES'[Quarter] )
        )
    )


    Cheers,
    Sturla