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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors