cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Post Partisan
Post Partisan

DAX variable to find earliest date on a graph's x axis

Hello,

 

I have tried the below code to find the earliest date on a graph's x axis...

 

VAR
    MinimumAxisWeek = min(ALLSELECTED('Calendar - Days'[Calendar Date (week bins)]))

 

.... but I am getting the error below:

 

"The MIN function only accepts a column reference as an argument."

 

Please could someone point me in the right direction?

 

Thanks,

 

CM

3 REPLIES 3
Highlighted
Resolver V
Resolver V

hi, 

the error message is correct, sometimes you need to combine these simple dax functions to get what you want.  

 

Use Min function to refer the date table, or column that you are using in your measure.   But then use the CALCULATE function to change the filter context of your measure so that it takes into account the selected values, perhaps something like: 

CALCULATE(MIN(Date[Date]), ALLSELECTED (Date[Date]))

(I haven't tested it out, but give it a go)

Highlighted
Super User IV
Super User IV

@CloudMonkey 


measure =
VAR
MinimumAxisWeek = minX(ALLSELECTED('Calendar - Days'),'Calendar - Days'[Calendar Date (week bins)])
return
MinimumAxisWeek



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Highlighted
Microsoft
Microsoft

Hi @CloudMonkey ,

 

The ALLSELECTED function gets the context that represents all rows and columns in the query, while keeping explicit filters and contexts other than row and column filters. You can also simply understand that the return value is a table.

Try to modify the formula like this:

 MinimumAxisWeek = CALCULATE(MIN('table'[date]),ALLSELECTED('table'[date]))

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors