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
music43
Advocate II
Advocate II

Stop measure results after a specific date

Hi

 

I am playing with the PBI Desktop (finance) dummy data to try and learn DAX. I am trying to stop Sales PY measure from returning a result after the last Sale date. I am pretty certain this DAX should work, which makes wonder if the problem is in the data/model.

music43_0-1654862707202.png

 

music43_1-1654862854431.png

Sales table

music43_2-1654862898221.png

 

Budget table (added by me - not in original dataset)

music43_3-1654862943658.png

 

Just in case you need to see, my [Sales Amt] measure:

Sales Amt =
SUMX(
    Sales,
    Sales[Units Sold] * Sales[Sale Price]
)


Can someone please help?

1 ACCEPTED SOLUTION
tamerj1
Community Champion
Community Champion

@music43 

Actually with my suggestion you should use MAX ( Date[Date] ) as condition not SELECTEDVALUE. 

What is happening hear is that SELECTEDVALUE returns blank everywhere while MAX ( Sales[Date] ) returns blank when there is no sale which did the job (blank = blank). But it won't work if you are slicing by Date instead of MonthYear. 

View solution in original post

8 REPLIES 8
n8ball
Advocate I
Advocate I

This is the way I do it. Add a DatesInThePast True / False column to your Date Table. 

Sales Amt PY = 
CALCULATE (
    [Sales Amt],
    CALCULATETABLE (
        SAMEPERIODLASTYEAR ( 'Date'[Date] ),
        'Date'[DatesInThePast] = TRUE
    )
)

 

@n8ball Thanks for the suggestion. I will check it out.

If you want to know more about why I'm using this pattern check out this very good article from SQLBI: Hiding future dates for calculations in DAX - SQLBI

Thanks again @n8ball. So many resources, it's difficult to keep track. Especially for someone starting out.
I would give you Kudos but I can't see an option for that. Has it been removed?

tamerj1
Community Champion
Community Champion

@music43 

VAR LastSalesDate =
CALCULATE (

    MAX ( Sales[Date] ), REMOVEFILTERS ( 'Date' ) 

)

Hi @tamerj1 

I tried what you suggested, but get the same result

music43_0-1654874573689.png

Interestingly, the MAX( Sales[Date] ) seems to be returning what I was expecting.

music43_1-1654874650584.png

 

 

tamerj1
Community Champion
Community Champion

@music43 

Actually with my suggestion you should use MAX ( Date[Date] ) as condition not SELECTEDVALUE. 

What is happening hear is that SELECTEDVALUE returns blank everywhere while MAX ( Sales[Date] ) returns blank when there is no sale which did the job (blank = blank). But it won't work if you are slicing by Date instead of MonthYear. 

@tamerj1 That did the trick - thanks
music43_0-1654875968400.png

 

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.