Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Year to year difference

How do i calculate year to year diffrence if my data type is in a whole number and not in "date" datatype. I only have sales data for 2021 and 2022. There are no month and day data. Most of tutorial/solution that I watch use calendar(dim date). But in my case I used only years data only which is in whole number datatype.

 

2 Replies

  • hi Anonymous 

    supposing you have a table like:

    YearSales
    20206
    20218
    20229
    20238

     

    try to add a calculated column like:

     

    YoY = 
    VAR _salespre = 
    MAXX(
        FILTER(
            data,
            data[Year]=EARLIER(data[Year])-1
        ),
        data[Sales]
    )
    RETURN
    IF(
        _salespre<>BLANK(),
        [Sales]-_salespre
    )

     

    it worked like:

  • or you plot a table visual with the year column and a measure like:

    YoY Measure = 
    VAR _salespre = 
    MAXX(
        FILTER(
            ALL(data),
            data[Year]=MAX(data[Year])-1
        ),
        data[Sales]
    )
    RETURN
    IF(
        _salespre<>BLANK(),
        MAX(data[Sales])-_salespre,
        ""
    )

    it worked like: