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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

DAX calculation based on Start Date and End Date

Hello everyone,

 

Need some help on some DAX calculation as I have very little knowledge about it.

So, I got this kind of data :

medwong_0-1607102978760.png

Then I added a Date Slicer which has Start and End Date like this :

medwong_1-1607103021252.png

How is the DAX formula looks like if I want to have :

1. Cost value at the beginning of the period selected (ex: 3/28/2020)

2. Cost value at the end of the period selected (ex: 8/29/2020)

 

Appreciate any help.

 

Thanks before.

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try these two measure expressions in Card visuals.

 

Starting Sum = var vMinDate = MIN(Table[Date])
return Calculate(SUM(Table[Cost]), FILTER(ALL(Table[Date]), Table[Date]<= vMinDate))

 

Ending Sum = SUM(Table[Cost])

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

6 REPLIES 6
mahoneypat
Microsoft Employee
Microsoft Employee

Yes.  The MIN is getting the min date in current context, which is defined by your slicer.  SELECTEDVALUE can be used only when there is a single value in scope.  Even when a single value is in scope, MIN/MAX/SUM/AVG are still often used instead of SELECTEDVALUE to harvest the value for calculations.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Many thanks for your guidance. 

mahoneypat
Microsoft Employee
Microsoft Employee

Please try these two measure expressions in Card visuals.

 

Starting Sum = var vMinDate = MIN(Table[Date])
return Calculate(SUM(Table[Cost]), FILTER(ALL(Table[Date]), Table[Date]<= vMinDate))

 

Ending Sum = SUM(Table[Cost])

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi @mahoneypat 

 

Many thanks. I tried and it is good. Just for my better understanding, when we have this code "var vMinDate = MIN(Table[Date])", doesn't it need to have like SELECTED or SELECTEDVALUE or we can actually just do it with what you've been described ?

 

I know it is working without it, but since I have slicer for the date, just wondering if just Min(Table[Date]) will refer to the slicer or not. Again it is just for my better understanding. I actually still confuse on this DAX features and how it works.

 

Thanks again.

 

 

mahoneypat
Microsoft Employee
Microsoft Employee

You can use LASTNONBLANKVALUE or FIRSTNONBLANKVALUE.  For example,

 

Min Cost = FIRSTNONBLANKVALUE(Table[Date], MIN(Table[Cost]))

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi @mahoneypat 

 

Sorry, I didn't get what you;re meaning. But gotta the feeling I probably didn;t explain correctly.

So what my intention is, as that is my inventory data, I want to have my inventory value at the beginning and end of the selected date.

 

I probably wrong, but I thought we have to do some CALCULATE function for totaling all the item's cost ? So on my mind is something like SUM through my table from the earliest transaction up to date specified in the Start Date, and then SUM through my table again but this time from earliest up to End Date. 

 

Refer to your suggestion, it looks like we only to get what is the cost of any item that happened on the Start or End Date, is it not ?

 

Thanks,

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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