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
SinclairFletche
New Member

get previous available date using dax?

im currently computing for gain/loss in the stock market, and the calendar is not perfect. for example today is monday, and i need to retrieve the data for friday. I am  trying to do it in dax with date values, but i only have data for weekdays, nothing on weekends. hope it make sense. Anyone can help please and thanks in advance.

1 ACCEPTED SOLUTION

@SinclairFletche 

Try this, replace source with the table name you have:

Gain / Loss = 
VAR x = 'Historical Data'[DATE]

RETURN

    CALCULATE(
        MAX('Historical Data'[SOURCE),
        FILTER(
            ALL('Historical Data'),
            'Historical Data'[DATE] < x
        )
    )

 

View solution in original post

4 REPLIES 4
ray_ux
Memorable Member
Memorable Member

@SinclairFletche  

using MAX() might work depending on your use case e.g., if you want the most recent date.
 

Hi Ray, okay i get the idea, thank you
Gain / Loss =
CALCULATE(
MAX('Calendar'[Date]),
FILTER(
ALL('Historical Data'[DATE]),
'Historical Data'[DATE] < MAX('Calendar'[Date])
)
)
mhmm, im just getting the same date instead of the previous day
what am i doing wrong?

@SinclairFletche 

Try this, replace source with the table name you have:

Gain / Loss = 
VAR x = 'Historical Data'[DATE]

RETURN

    CALCULATE(
        MAX('Historical Data'[SOURCE),
        FILTER(
            ALL('Historical Data'),
            'Historical Data'[DATE] < x
        )
    )

 

working now. Thanks

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.