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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

@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
Helper I
Helper 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
Super User
Super User

@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

 

 

@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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors