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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Maikeru
Helper II
Helper II

Calculating Min/Max date columns based on selected values

Hi,

 

I am trying to insert 2 new columns into my dataset containing the MIN/MAX values of the date slicer.

screenshot2.png

 

I was thinking about the following DAX, but it throws me a circular dependency error.

Min selected date (ALLSELECTED) = 
CALCULATE( MIN('Calendar'[Date]), ALLSELECTED('Calendar'[Date]) )

Appreciate if anyone would have an idea.

 

Here is the pbix file:
https://drive.google.com/file/d/1HRjJxByXmLVrgoH9IDnOAlEKHbGytiQo/view?usp=sharing

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

 

You have to write measures, not calculated column formulas.  Delete all column from the Calendar Table except the Date column.  Write these measures

 

Minimum date = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

Maximum date = CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
CheenuSing
Community Champion
Community Champion

Hi @Maikeru

 

 

Try the following as columns

 

 

MinDate = CALCULATE( MIN('01-MasterCalendar'[Date]),
                       FILTER(ALL('01-MasterCalendar'[Date]),'01-MasterCalendar'[Year] =YEAR('01-MasterCalendar'[Date]) ))

 

MaxDate = CALCULATE( Max('01-MasterCalendar'[Date]),
                       FILTER(ALL('01-MasterCalendar'[Date]),'01-MasterCalendar'[Year] =YEAR('01-MasterCalendar'[Date]) ))

 

Replace '01-MasterCalendar' with your calendar table name.

 

Using these expressions it will generate MIn and Max dates for each year in the calendar table.

 

 

If this works for you please accept this as solution and also give KUDOS.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
Ashish_Mathur
Super User
Super User

Hi,

 

You have to write measures, not calculated column formulas.  Delete all column from the Calendar Table except the Date column.  Write these measures

 

Minimum date = CALCULATE(MIN('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

Maximum date = CALCULATE(MAX('Calendar'[Date]),ALLSELECTED('Calendar'[Date]))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

What are the min and max date codes doing and when to use it?

Appreciate your explanation.

Hi,

It fetches the first and last date selected in the slicer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

What I meant to understand is what the ALLSELECTED doing inside the CALCULATE function.

Is it always good to use ALLSELECTED while working with dates?

Hi @Ashish_Mathur , is it possible have this as a column?

 

im saying this because im using a Matrix table so it doesnt allow measures in the rows.

Hi,

Switch to a matrix visual and in the formatting pane, under the Values group, turn on Show on rows.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you @Ashish_Mathur!
That's exactly what I was looking for!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.