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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
wokka
Helper IV
Helper IV

Adding filter via code to an existing table on desktop - how?

I have an existing table that I created by clicking on a table visualisation, then manually dropped a measure and dimension columns into it. 

 

I would like to add a date filter via a custom measure to the table programatically.  Normally when I add a filter to a table its by  manual drag and drop then manual configuration of the filter. The date is to be extracted from a slicer drop down value from the desktop, and stored in a cutom measure, then passed to the filter on the table.

 

I havent done this before, so any help appreciated.

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Akash_Varuna
Super User
Super User

Hi @wokka You can try by creating a measure using SELECTEDVALUE to capture the slicer date (e.g., SelectedDate = SELECTEDVALUE('DateTable'[Date])). Then, create another measure to filter rows, such as FilteredTable = IF(MAX('YourTable'[DateColumn]) = [SelectedDate], 1, 0). Add this measure to the table visual’s filters pane and set it to is 1.

View solution in original post

3 REPLIES 3
v-achippa
Community Support
Community Support

Hi @wokka,

 

Thank you for reaching out to Microsoft Fabric Community.

 

Make sure the fact table has a proper relationship to the calendar table on a date field.

Use this below mesure:

ShowPreviousMonthRows =

VAR SelectedMonth = SELECTEDVALUE('Calendar'[Month])

VAR TargetMonth = SelectedMonth - 1

VAR RowMonth = MONTH(MAX('Yourtable'[Date])) 

RETURN

    IF(RowMonth = TargetMonth, 1, 0)

 

Add this measure to the filters pane of the table visual and set the filter condition to 1.

This will ensure the table only shows rows from the month prior to the one selected in the slicer.

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Thanks and regards,

Anjan Kumar Chippa

Akash_Varuna
Super User
Super User

Hi @wokka You can try by creating a measure using SELECTEDVALUE to capture the slicer date (e.g., SelectedDate = SELECTEDVALUE('DateTable'[Date])). Then, create another measure to filter rows, such as FilteredTable = IF(MAX('YourTable'[DateColumn]) = [SelectedDate], 1, 0). Add this measure to the table visual’s filters pane and set it to is 1.

Hi, thank you for your help.

 

My slicer has an output of 4 ( the month of april ), which i have confirmed is correct

I get my [month behind] using this measure :    [month behind] = SELECTEDVALUE('Calendar'[Month]) -1

which gives value of 3 ( month of march )
When I drag and drop [month behind] onto the desktop , I see a value of 3, so that is OK.
 
When I create this new measure :
FilteredTable = IF(MAX('Calendar'[Month]) = [month behind], 1, 0)
and set it to 1 as you suggested, unfortunately I get no data unfortunately ( the output is blank ).

 

Not sure why ?

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.