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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jgrima
New Member

PowerBI custom filter

Hello, I'm trying to create an special filter for my table.

 

I have Year and Month columns, and I need an slicer that shows every year (2022, 2023, 2024...). When selecting a year, let's say 2024, I need to filter the table by every month of this year, and last year's December.

 

So, if I select 2024, I will see data for:

Dec 23  Jan 24  Feb 24  Mar 24  Apr 24  May 24  Jun 24  Jul 24  Aug 24  Sep 24  Oct 24  Nov 24  Dec 24

If I select 2023:
Dec 22  Jan 23  Feb 23  Mar 23  Apr 23  May 23  Jun 23  Jul 23  Aug 23  Sep 23  Oct 23  Nov 23  Dec 23

 

Does anybody knows how could I implement this?
Thank you.

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@jgrima ,Ensure you have a date table that includes columns for Year, Month, and Date. If you don't have one, you can create it using DAX.

 

In your date table, add a custom column to identify the previous year's December for each year. You can use the following DAX formula:

PreviousDecember = IF(MONTH([Date]) = 12, YEAR([Date]), YEAR([Date]) - 1)

 

Add a slicer to your report and set it to filter by the Year column from your date table.
Create a Measure for Filtering:

 

Create a measure that will be used to filter the table based on the selected year and the previous year's December. You can use the following DAX formula:


FilterMeasure =
VAR SelectedYear = SELECTEDVALUE('DateTable'[Year])
RETURN
IF(
YEAR('YourTable'[Date]) = SelectedYear ||
(YEAR('YourTable'[Date]) = SelectedYear - 1 && MONTH('YourTable'[Date]) = 12),
1,
0

 

Apply the Measure as a Visual Level Filter:
Add your table visual to the report.
Drag the FilterMeasure to the Filters pane for the table visual.
Set the filter to show only values where FilterMeasure is 1.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

1 REPLY 1
bhanu_gautam
Super User
Super User

@jgrima ,Ensure you have a date table that includes columns for Year, Month, and Date. If you don't have one, you can create it using DAX.

 

In your date table, add a custom column to identify the previous year's December for each year. You can use the following DAX formula:

PreviousDecember = IF(MONTH([Date]) = 12, YEAR([Date]), YEAR([Date]) - 1)

 

Add a slicer to your report and set it to filter by the Year column from your date table.
Create a Measure for Filtering:

 

Create a measure that will be used to filter the table based on the selected year and the previous year's December. You can use the following DAX formula:


FilterMeasure =
VAR SelectedYear = SELECTEDVALUE('DateTable'[Year])
RETURN
IF(
YEAR('YourTable'[Date]) = SelectedYear ||
(YEAR('YourTable'[Date]) = SelectedYear - 1 && MONTH('YourTable'[Date]) = 12),
1,
0

 

Apply the Measure as a Visual Level Filter:
Add your table visual to the report.
Drag the FilterMeasure to the Filters pane for the table visual.
Set the filter to show only values where FilterMeasure is 1.




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.