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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
sumon_51
Regular Visitor

Need Help in DAX

i have fact table where have data for various date, i have made a calendar table using calendar() and max and min,and link this calendar table to fact table,  from this calendar table i have made 2 slicer month and date
my requirement:
1. if i select a date from my 2 slicer ie. from month i select sept and from date slicer i select 23, i want a dax that will show previous available date in card, that is 18 sept, as there is no data for 19-22 sept, is this possible 

3 ACCEPTED SOLUTIONS
FBergamaschi
Solution Sage
Solution Sage

Hi @sumon_51 ,

first of all you need to select also a year (unless you loaded only facts from a single year but in any case it is better to fix a year or in furture refreshes if you include multiple years fact you get an issue)

 

That said, here is the code

 

Imponibile Prev Day =
VAR SelectedDate = SELECTEDVALUE( 'Calendar'[Date] )
VAR PrevDatewithSales =
CALCULATE(
    MAX ( Sales[OrderDate] ),
    Sales[OrderDate] < SelectedDate,
    REMOVEFILTERS( 'Calendar' )
)
RETURN
CALCULATE(
    [YourMeasure],
    'Calendar'[Date] = PrevDatewithSales
)
 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

View solution in original post

danextian
Super User
Super User

Hi @sumon_51 

This measure will return the latest date with data on or before the currently selected date

Latest Date With Value = 
CALCULATE (
        // Find the latest date (up to the currently selected date)
        // where [Sum of Sales] is not blank
        LASTNONBLANK ( Dates[Date], [Sum of Sales] ),
        FILTER (
            ALL ( Dates ),                  // remove filters to scan the full date range
            Dates[Date] <= MAX ( Dates[Date] ) // only keep dates up to the current context date
        )
    )

Below will return a value based on the date above

Sales - Latest Available Date = 
VAR LastNonBlankDate =
    CALCULATE (
        // Find the latest date (up to the currently selected date)
        // where [Sum of Sales] is not blank
        LASTNONBLANK ( Dates[Date], [Sum of Sales] ),
        FILTER (
            ALL ( Dates ),                  // remove filters to scan the full date range
            Dates[Date] <= MAX ( Dates[Date] ) // only keep dates up to the current context date
        )
    )
RETURN
    CALCULATE (
        // Return the sales value corresponding to that last nonblank date
        [Sum of Sales],
        FILTER (
            ALL ( Dates ),                  // remove filters to allow exact match
            Dates[Date] = LastNonBlankDate  // isolate only the last valid date found above
        )
    )

 In the image below, I selected Jan 4 which doesn't have a value so it shows the value for Jan 3 instead

danextian_0-1758976738078.png

 





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.

View solution in original post

raja1992
Resolver I
Resolver I

I had a similar case in my sales fact table where data wasn’t available for all calendar dates. For example, my calendar showed 19th–22nd Sept, but sales were only on 18th and 23rd.

 

What I did was create a measure to pick the last available date before the selected date. Here’s a DAX pattern that worked for me:

PrevAvailableDate =
CALCULATE (
    MAX ( FactTable[Date] ),
    FILTER (
        ALL ( FactTable ),
        FactTable[Date] < MAX ( 'Calendar'[Date] )
    )
)

 

  • MAX('Calendar'[Date]) → picks the selected date from the slicer (like 23-Sep).

  • The FILTER goes back into the fact table and finds the largest date that is less than the selected date (in your case, 18-Sep).

Example from my model:

  • Calendar selected = 23-Sep

  • Fact table dates = 15, 18, 23 Sept

  • Measure result = 18-Sep

Just drop this measure in a card visual and it will always show the latest available date before the slicer date.

 

Small tip: If you also want to display the actual value from that date (like Sales), just replace MAX(FactTable[Date]) with your measure inside the same pattern.

View solution in original post

6 REPLIES 6
raja1992
Resolver I
Resolver I

I had a similar case in my sales fact table where data wasn’t available for all calendar dates. For example, my calendar showed 19th–22nd Sept, but sales were only on 18th and 23rd.

 

What I did was create a measure to pick the last available date before the selected date. Here’s a DAX pattern that worked for me:

PrevAvailableDate =
CALCULATE (
    MAX ( FactTable[Date] ),
    FILTER (
        ALL ( FactTable ),
        FactTable[Date] < MAX ( 'Calendar'[Date] )
    )
)

 

  • MAX('Calendar'[Date]) → picks the selected date from the slicer (like 23-Sep).

  • The FILTER goes back into the fact table and finds the largest date that is less than the selected date (in your case, 18-Sep).

Example from my model:

  • Calendar selected = 23-Sep

  • Fact table dates = 15, 18, 23 Sept

  • Measure result = 18-Sep

Just drop this measure in a card visual and it will always show the latest available date before the slicer date.

 

Small tip: If you also want to display the actual value from that date (like Sales), just replace MAX(FactTable[Date]) with your measure inside the same pattern.

danextian
Super User
Super User

Hi @sumon_51 

This measure will return the latest date with data on or before the currently selected date

Latest Date With Value = 
CALCULATE (
        // Find the latest date (up to the currently selected date)
        // where [Sum of Sales] is not blank
        LASTNONBLANK ( Dates[Date], [Sum of Sales] ),
        FILTER (
            ALL ( Dates ),                  // remove filters to scan the full date range
            Dates[Date] <= MAX ( Dates[Date] ) // only keep dates up to the current context date
        )
    )

Below will return a value based on the date above

Sales - Latest Available Date = 
VAR LastNonBlankDate =
    CALCULATE (
        // Find the latest date (up to the currently selected date)
        // where [Sum of Sales] is not blank
        LASTNONBLANK ( Dates[Date], [Sum of Sales] ),
        FILTER (
            ALL ( Dates ),                  // remove filters to scan the full date range
            Dates[Date] <= MAX ( Dates[Date] ) // only keep dates up to the current context date
        )
    )
RETURN
    CALCULATE (
        // Return the sales value corresponding to that last nonblank date
        [Sum of Sales],
        FILTER (
            ALL ( Dates ),                  // remove filters to allow exact match
            Dates[Date] = LastNonBlankDate  // isolate only the last valid date found above
        )
    )

 In the image below, I selected Jan 4 which doesn't have a value so it shows the value for Jan 3 instead

danextian_0-1758976738078.png

 





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.

Thank for you solution
i need an extra solution 

1. if select jan-4 my card will show total sales for jan 4, if jan 4 has no data then it will show blank. if blank or not blank, need % changes compare with previous available date, for example i select jan 5 value is 1119 as jan 4 has no value so it will consider jan 3 value is 393 to compare and result should be 184.73 %

Is not this the diference in pct between

 

[YourMeasure] and 

 

[YourMeasurePrev Day] =
VAR SelectedDate = SELECTEDVALUE'Calendar'[Date] )
VAR PrevDatewithSales =
CALCULATE(
    MAX ( Sales[OrderDate] ),
    Sales[OrderDate] < SelectedDate,
    REMOVEFILTERS'Calendar' )
)
RETURN
CALCULATE(
    [YourMeasure],
    'Calendar'[Date] = PrevDatewithSales
)
 
?
 
If yes,
DIVIDE (
          [YourMeanure] - [YourMeasurePrev Day],
          [YourMeasurePrev Day]
)

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

FBergamaschi
Solution Sage
Solution Sage

Hi @sumon_51 ,

first of all you need to select also a year (unless you loaded only facts from a single year but in any case it is better to fix a year or in furture refreshes if you include multiple years fact you get an issue)

 

That said, here is the code

 

Imponibile Prev Day =
VAR SelectedDate = SELECTEDVALUE( 'Calendar'[Date] )
VAR PrevDatewithSales =
CALCULATE(
    MAX ( Sales[OrderDate] ),
    Sales[OrderDate] < SelectedDate,
    REMOVEFILTERS( 'Calendar' )
)
RETURN
CALCULATE(
    [YourMeasure],
    'Calendar'[Date] = PrevDatewithSales
)
 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

sumon_51
Regular Visitor

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors