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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
js2246
Frequent Visitor

Dynamic Date

I have a case where I have mulitple dates that define unique variables and I want to be able to customize a date range where people can get totals based on the date range selected.

 

So for instance I might have Dates that look like this:

Date1Date2Date3Date4Date5Date6
24-Dec-1631-Jan-1731-Jan-17...
8-Feb-178-Feb-178-Feb-178-Feb-1715-Feb-1713-Feb-17
15-Apr-1713-Apr-1713-Apr-1713-Apr-1713-Apr-1713-Apr-17
8-Feb-1712-Feb-178-Feb-1712-Feb-178-Feb-179-Feb-17
5-Apr-175-Apr-175-Apr-1710-Apr-175-Apr-175-Apr-17
21-Apr-1721-Apr-1723-Apr-17.21-Apr-1729-May-17
25-Mar-1720-Mar-1725-Mar-1703-Apr-1718-Feb-1722-Mar-17
31-Jan-1728-Jan-1731-Jan-1731-Jan-1731-Jan-1731-Jan-17
8-Apr-179-Apr-178-Apr-1710-Apr-178-Apr-1715-Apr-17
26-Jan-1731-Jan-1731-Jan-1702-Mar-1731-Apr-1703-Feb-17

 

So I might have the variables:

var1=sum(if (Date1< 31-Jan-17 , 1, 0))

var2=sum(if (Date2< 31-Jan-17 , 1, 0))

var3=sum(if (Date3< 31-Jan-17 , 1, 0))

etc

 

but I want to be able to change the 31-Jan-17 dynamically based on a date selected how would be the best way to do this?

9 REPLIES 9
parry2k
Super User
Super User

you need a date dimension table in your model, from that table use date as a slicer and in your formula replace "31-Jan-2017" with MAX(DateTable[Date])

 

 



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.

Thank you for your response but could you provide more details please. I'm newer to this.

At what point do I do this? 

If I create a date table based on entered data then try to create new columns for my calculated variables based on that datetable[date] then I would have to establish some sort of relationship between the date table and my original table correct? And I can't establish a relationship between the datatable[date} and all of my dates, correct?

 

I tried no relationship and created new column  var1 = if (sheet1[Date1]<max(datetable[date]),1,0) 

and for daterange[date] i filtered to one date value but my var1 result is not effected.

no you don't need to establish relation, it will work without relation, you just want to get date from the slicer.

 

https://www.mssqltips.com/sqlservertip/4857/creating-a-date-dimension-table-in-power-bi/

 

http://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-1-calendar-columns



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.

I don't know what I'm doing wrong then because I can't get the slicer to change anything.  Var1 is set to the sum, and clicking on different dates doesn't effect it at all.  Do you see something I'm doing wrong?

Calc.JPG

 

Seems like you are adding var1 as column whereas it need to be Measure since you are using sum aggregation.



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.

I'm not sure how to write this as a measure. 

I get the error a single value for 'Date1' in table 'Sheet1 cannot be determined. This can happen when a measure formula refers to a column that contains many values whithout specifying an aggregation.... 

 

I wouldn't think aggregating the dates would work since the vars are defined independently from them

i guess it need bit more tweaking, can you share your data in excel sheet and get back to you with solution. cheers!



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.

I was just using the example data and variable definitions shown in the original post. I can't share my actual data of millions of records but I figure if we could get this short example problem working then I could apply the solution to my actual data. Thanks for your help!

no problem, will work on it tomorrow.



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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.