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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Thomasshepherd2
Frequent Visitor

Using selectedvalue to retrieve a date returns 1899 date

Hi there

I want to have a column in a graph that calculates the profit in a graph for the year before the selected date.

Out Fin year is a bit wonky so that is why there are 11 and 12’s

This is the measure I have :

Last Year MTD Profit =

VAR SelectedDate = SELECTEDVALUE('Calendar'[Date])

VAR SelectedYear = YEAR(SelectedDate)

VAR SelectedMonth = MONTH(SelectedDate)

VAR SelectedDay = DAY(SelectedDate)

 

VAR StartDate =

    IF(

        MONTH(SelectedMonth) IN {11, 12},

        DATE(SelectedYear - 1, 11, 01),

        DATE(SelectedYear - 2, 11, 01)

    )

 

VAR EndDate =

    IF(

        MONTH(SelectedMonth) IN {11, 12},

        DATE(SelectedYear, 10, 31),

        DATE(SelectedYear - 1, 10, 31)

    )

 

VAR _measure2 =

    CALCULATE(

        SUM('Fact Finance Combined'[Redacted]),

        DATESBETWEEN('Fact Finance Combined'[Redacted], StartDate, EndDate)

    )

 

RETURN

    StartDate

    --EndDate

    --_measure2

 

When I put in a card to test the start and end dates it shows be the below

 

Thomasshepherd2_0-1714624005273.png

 

 

Thomasshepherd2_1-1714624005275.png

 

1 ACCEPTED SOLUTION

Fixed it by using LastDate in the selected year VAR

Last Year MTD Profit =

VAR SelectedDate = LASTDATE(ALLSELECTED('Calendar'[Date]))

VAR SelectedYear = YEAR(SelectedDate)-1

VAR SelectedMonth = MONTH(SelectedDate)

VAR SelectedDay = DAY(SelectedDate)

 

VAR StartDate =

    IF(

        MONTH(SelectedMonth) IN {11, 12},

        DATE(SelectedYear - 1, 11, 01),

        DATE(SelectedYear - 2, 11, 01)

    )

 

VAR EndDate =

    IF(

        MONTH(SelectedMonth) IN {11, 12},

        DATE(SelectedYear, 10, 31),

        DATE(SelectedYear - 1, SelectedMonth, SelectedDay)

    )

 

VAR _measure2 =

    CALCULATE(

        SUM('Fact Finance Combined'[Redacted]),

        DATESBETWEEN('Fact Finance Combined'[Redacted], StartDate, EndDate)

    )

 

RETURN

    --StartDate

    --EndDate

    _measure2

 

View solution in original post

3 REPLIES 3
danextian
Super User
Super User

Hi @Thomasshepherd2 ,

 

By default, SELECTEDVALUE returns blank if there are more than one values returned. On or before/on or after feature of the slicer returns mutliple values.  Use either LASTDATE, FIRSTDATE, MIN or MAX.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hey Thanks for the reply,

 

when i try to use min max first last it says it needs a column but the calendar[date] is a column.

 

i need to use the slicer to get the date as people will adjust the date which needs to then filter the matrix.

 

appreciate any additional assistance - i have looked through forumns and reddit and not finding much.

Fixed it by using LastDate in the selected year VAR

Last Year MTD Profit =

VAR SelectedDate = LASTDATE(ALLSELECTED('Calendar'[Date]))

VAR SelectedYear = YEAR(SelectedDate)-1

VAR SelectedMonth = MONTH(SelectedDate)

VAR SelectedDay = DAY(SelectedDate)

 

VAR StartDate =

    IF(

        MONTH(SelectedMonth) IN {11, 12},

        DATE(SelectedYear - 1, 11, 01),

        DATE(SelectedYear - 2, 11, 01)

    )

 

VAR EndDate =

    IF(

        MONTH(SelectedMonth) IN {11, 12},

        DATE(SelectedYear, 10, 31),

        DATE(SelectedYear - 1, SelectedMonth, SelectedDay)

    )

 

VAR _measure2 =

    CALCULATE(

        SUM('Fact Finance Combined'[Redacted]),

        DATESBETWEEN('Fact Finance Combined'[Redacted], StartDate, EndDate)

    )

 

RETURN

    --StartDate

    --EndDate

    _measure2

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.