0
votes

I have two tables: a fact-table with hours spent, and a date dimensions table.

factTableHours:
| employeeName | hours | datekey |

dimDate: (from year 2000-2030)
| datekey | year | month | day |

I'm trying to create a simple estimate of how many hours an employee is going to spend in the future by looking at the hours he spent the last whole year.
It's similar to the SAMEPERIODLASTYEAR function, but i want a specific year based on today's date.
So, if I did it today, I would like it to return the time registered in 2015,
in order to get an estimate of how many hours he will spend in the coming years, 2016, 2017, 2018...

3

3 Answers

0
votes

You can create a measure that calculates the last year hours.

Using the TODAY() function you will get the today's date, so we need to substract one year.

HoursLastYear =
CALCULATE (
    SUM ( factTableHours[hours] ),
    FILTER (
        dimDate,
        dimDate[datekey]
            = DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
    )
)

Let me know if this helps.

0
votes

Try something like this - With this Statement you get the figures from last year:

[PY Sales] = CALCULATE([Sales Amount]),DATEADD('Date'[Date],-1,YEAR)

BTW - here is a good reference for DAX Time Patterns:

http://www.daxpatterns.com/time-patterns/

0
votes

I found a solution with the help of this page: https://www.sqlbi.com/articles/week-based-time-intelligence-in-dax/
I only needed another column in my time dimension, the day number of the year

hoursIn2015 :=
    IF (
    HASONEVALUE ( dimDate[year] ),
    CALCULATE (
        SUM ( factTableHours[hours] ),
        FILTER (
            ALL ( dimDate),
            dimDate[year] = 2015
                && CONTAINS(
                    VALUES ( dimDate[Day number in year] ),
                    dimDate[Day number in year],
                    dimDate[Day number in year] )
        )
    ),
    BLANK ()
)