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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kkalyanrr
Helper V
Helper V

earliest date values in the absence of matching date

Hello Team,

 

I'm trying put a chart which filters with dates. But in my dataset there are few dates missing. Is there a way to get the values(Sales) which are very close to previous day(earliest previous day) in case user enters a date9in the date filter) which is not in the dataset.

 

RT.PNGRT2.PNG

 

 

 

 

 

Thanks,

Kalyan..

1 ACCEPTED SOLUTION

@kkalyanrr,

 

You may use the following DAX.

Measure =
VAR d =
    MAX ( Sheet2[Date] )
RETURN
    MAXX (
        TOPN ( 1, FILTER ( ALL ( Sheet3 ), Sheet3[Date] <= d ), Sheet3[Date], DESC ),
        Sheet3[Sales Target]
    )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-chuncz-msft
Community Support
Community Support

@kkalyanrr,

 

You may refer to the following measure.

Measure =
VAR d =
    MIN ( 'Calendar'[Date] )
RETURN
    MAXX (
        TOPN ( 1, FILTER ( Table1, Table1[Date] <= d ), Table1[Date], DESC ),
        Table1[Sales]
    )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-chuncz-msft and @Smauro

 

Sorry , it didn't worked out well for me..

 

Please take a look at screenshots and let me know if I missed any thing..
I'm still unable to get Targets filling up for all the dates.. 

I've tried using bot the formulae..

 

Measure =   
VAR d =MIN ( 'Calendar'[Date] )

RETURN
MAXX (TOPN ( 1, FILTER ( Sheet3, Sheet3[Date] <= d ), Sheet3[Date], DESC ),Sheet3[Sales Target])

Measure 2 =
VAR x = CALCULATE ( COUNTROWS ( Sheet3 ) + 0, FILTER ( Sheet3, Sheet3[Date] = MAX('calendar'[Date].[Date] )) )
VAR y = IF ( x = 0, CALCULATE ( MAX ( Sheet3[Date] ), FILTER ( Sheet3, Sheet3[Date] <= MAX('calendar'[Date].[Date] ))), MAX('calendar'[Date].[Date] ))

RETURN
CALCULATE ( MAX ( Sheet3[Sales Target] ), FILTER ( Sheet3, Sheet3[Date] <= y && Sheet3[Date] >= y ) )




Dashboard ChartDashboard Chart
Dataset 1Dataset 1Dataset 2Dataset 2Calendar DatasetCalendar DatasetLinkLink

@kkalyanrr,

 

You may use the following DAX.

Measure =
VAR d =
    MAX ( Sheet2[Date] )
RETURN
    MAXX (
        TOPN ( 1, FILTER ( ALL ( Sheet3 ), Sheet3[Date] <= d ), Sheet3[Date], DESC ),
        Sheet3[Sales Target]
    )
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Smauro
Solution Sage
Solution Sage

Hey there @kkalyanrr. I'm guessing all this is happening because you're filtering from a separate date table. If not, then your slicer will not display the dates that don't exist in your dataset.

So, I guess you now have something like this:

 

Sales =
CALCULATE (
    SUM ( Table[Sales] ),
    FILTER (
        Table,
        Table[Date] >= 'Calendar'[Date]
            && Table[Date] <= 'Calendar'[Date]
    )
)

 

 

What you could do, is this:

SalesNEW =
VAR x =
    CALCULATE (
        COUNTROWS ( Table ) + 0,
        FILTER ( Table, Table[Date] = 'Calendar'[Date] )
    )
VAR y =
    IF (
        x = 0,
        CALCULATE (
            MAX ( Table[Date] ),
            FILTER ( Table, Table[Date] <= 'Calendar'[Date] )
        ),
        'Calendar'[Date]
    )
RETURN
    CALCULATE (
        SUM ( Table[Sales] ),
        FILTER ( Table, Table[Date] <= y && Table[Date] >= y )
    )

which basically checks if there exists a sale on this day, and if not it finds the first previous day with sales and and then calculates the sales on a same manner.

I don't really understand though why you'd like to display sales on a day where there weren't any, but what can I do 🙂

Hope that helps !

 




Spyros Mavroforos

Data Consultant


Find me on LinkedIn or drop me an email

eSpyros

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.