Forum Discussion

Bare's avatar
Bare
Frequent Visitor
6 years ago

DAX measure to get first value dynamically with different time period windows

Hi All,

I need your help. I have researched possible solutions on this forum & the wider net, but couldn't find what I'm looking for. Much appreciate any help, pointer, assistance!

Scenario: I have a table with 3 columns, date & closing price & type. This of course links to a date table.

Requirement: I want to obtain the first price information per type against different time periods. Below image shows expected outcome for a 7-day period (column 'starting price', which is ultimately used as input to obtain column 'cumulated gains'):

 

 

Objective: using above for context, I want to obtain first value as repeating values for that specific time window (in this case 7-day) as shown in column 'Starting price'. This value is then used to calculate column 'Cumulated gains' from start of each window

what I did so far: I used 'FIRSTDATE' function to obtain the first value. It works fine if only I wanted a card. However, when I plugged this in a more elaborate DAX statement, I get an error (as usual, undescriptive "table of multiple values was supplied where a single value was expected". Ok descriptive, but i have no clue where to begin!). See DAX code below:

 

 

Who knows? Probably, I am over complicating what is probably something easy. Hence my turning to you for help.

 

Looking forward to your assistance & help for pointers to what I'm doing wrong

 

Thanks

Bare

2 Replies

  • Bare one thing is not clear what define the 7 day period. Mon - Sun, sun to mon or something else?

    • Bare's avatar
      Bare
      Frequent Visitor

      Hi parry2k 

      Thanks for having a look.

      I define Mon as 1, Sun as 7 per default. In praticse, the time window will be longer in years: 1, 3, & 5 yrs. I used here days for illustrative purposes only.

      I've simply left the definition of the time period to the DATEADD function. Hence in the DAX code, I have used a 'nonblank' VAR to get the first non blank date if at the end of DATEADD we have a weekend.

       

      I hope this helps and answers your question