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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
armehraban
New Member

Filter table visual based on closest date to slicer in power bi

 

I have a table and a slicer (showing today’s date by default).  I want when a user select a date from slicer, the table shows the closest date (date column in the table visual) to the selected in slicer.

armehraban_0-1705890235814.png

 

 

I tried to create a measure that shows max date less than selected date in slicer:

 

Also a filter that shows which records should show and which is not:

armehraban_2-1705890235821.png

 


Filter = IF(FORMAT('BankCard AccountSummary'[Date], "dd/MM/YYYY") = FORMAT([max dates], "dd/MM/YYYY") ,1,0)

 

And used that filter in filter section.

 

The “max dates” shows me the correct number but when I want to compare it with date column in the table visual, the filter measure doesn’t show correct data.

I tried to convert both “max dates” and date column to the same format both still didn’t work.                     

 

1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Hi @armehraban 

 

Use the following Dax to get the "max date" column

max date = 
VAR SelectedDate = SELECTEDVALUE('Start Date'[Date])
VAR ClosestDate =
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] <= SelectedDate
        )
    )
RETURN
    IF(
        MIN('Table'[Date]) <= SelectedDate,
        ClosestDate,
        BLANK()
    )

 

Use the following Dax to get the "Date Difference Measure" column

Date Difference Measure = 
VAR SelectedDate = SELECTEDVALUE('Start Date'[Date])
VAR ClosestDateMeasure =
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] <= SelectedDate
        )
    )
RETURN
    DATEDIFF(ClosestDateMeasure, MAX('Table'[Date]), DAY)

 

Use the following Dax to get the "Date Format Match Measure" column

 

Date Format Match Measure = 
IF (
    FORMAT(MAX('Table'[Date]), "dd/mm/yyyy") = FORMAT([max date], "dd/mm/yyyy"),
    1,
    0
)

 

 

This is the result you want

vjialongymsft_0-1705990105486.png

 

If I misunderstand what you mean, please provide your sample PBIX file along with the result you want

 

 

Best Regards,

Jayleny

 

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

2 REPLIES 2
v-jialongy-msft
Community Support
Community Support

Hi @armehraban 

 

Use the following Dax to get the "max date" column

max date = 
VAR SelectedDate = SELECTEDVALUE('Start Date'[Date])
VAR ClosestDate =
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] <= SelectedDate
        )
    )
RETURN
    IF(
        MIN('Table'[Date]) <= SelectedDate,
        ClosestDate,
        BLANK()
    )

 

Use the following Dax to get the "Date Difference Measure" column

Date Difference Measure = 
VAR SelectedDate = SELECTEDVALUE('Start Date'[Date])
VAR ClosestDateMeasure =
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALL('Table'),
            'Table'[Date] <= SelectedDate
        )
    )
RETURN
    DATEDIFF(ClosestDateMeasure, MAX('Table'[Date]), DAY)

 

Use the following Dax to get the "Date Format Match Measure" column

 

Date Format Match Measure = 
IF (
    FORMAT(MAX('Table'[Date]), "dd/mm/yyyy") = FORMAT([max date], "dd/mm/yyyy"),
    1,
    0
)

 

 

This is the result you want

vjialongymsft_0-1705990105486.png

 

If I misunderstand what you mean, please provide your sample PBIX file along with the result you want

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

That should work as you described.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!