Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Bare
Frequent Visitor

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'):

 

Desired outcome.JPG

 

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:

 

dax code.JPG

 

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 2
parry2k
Super User
Super User

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



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.