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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
mtomova
Helper III
Helper III

MIN and FIRSTNONBLANK functions returns wrong value from a slicer

Hi!

 

I have a dynamic title card, in which I want to show the range selected in a slicer.

The slicer holds the Month Year values for few years period.

 

I am using the following DAX to get the selected range:

Op Forecast - Cap Spend Months Rng = 

"Capital Spend Forecast for " &

FIRSTNONBLANK('Calendar Calcs'[Year Month], MIN('Calendar Calcs'[Year Month])) & " - " & LASTNONBLANK('Calendar Calcs'[Year Month], MAX('Calendar Calcs'[Year Month]))

 

In the slicer I have selected Jan 2023 + Feb 2023 + March 2023, so what I exptect to see is:

"Capital Spend Forecast for Jan 2023 - March 2023", but instead I get Feb 2023 - March 2023.


I am pretty sure that this happens, because t
he Year Month column is formatted as Text, 

but I have also tried the following code, to get first and last non blank values from the selection in the slicer

 

Op Forecast - Cap Spend Months Rng =
"Capital Spend Forecast for " &
FIRSTNONBLANK('Calendar Calcs'[Year Month], 1) & " - " & LASTNONBLANK('Calendar Calcs'[Year Month], 1)


and the result is again Feb 2023 - March 2023, instead of Jan 2023 - March 2023

Any advice how to approach this challenge will be highly appreciated!

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

You are correct about the text column so it is getting sorted alphabetically.  We need to use a numeric column to get the lowest and highest like this.

 

Op Forecast - Cap Spend Months Rng = 

"Capital Spend Forecast for " & 
VAR _Min = MIN('Calendar Calcs'[Date])
VAR _Max = MAX('Calendar Calcs'[Date])
RETURN
CALCULATE(SELECTEDVALUE('Calendar Calcs'[Year Month]),'Calendar Calcs'[Date]=_Min) & " - " & CALCULATE(SELECTEDVALUE('Calendar Calcs'[Year Month]),'Calendar Calcs'[Date]=_Max)

jdbuchanan71_0-1672838150204.png

 

 

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

You are correct about the text column so it is getting sorted alphabetically.  We need to use a numeric column to get the lowest and highest like this.

 

Op Forecast - Cap Spend Months Rng = 

"Capital Spend Forecast for " & 
VAR _Min = MIN('Calendar Calcs'[Date])
VAR _Max = MAX('Calendar Calcs'[Date])
RETURN
CALCULATE(SELECTEDVALUE('Calendar Calcs'[Year Month]),'Calendar Calcs'[Date]=_Min) & " - " & CALCULATE(SELECTEDVALUE('Calendar Calcs'[Year Month]),'Calendar Calcs'[Date]=_Max)

jdbuchanan71_0-1672838150204.png

 

 

Wow, that is exactly what I was after!

Thank you for your help!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors