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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
JonasMarty
New Member

Filter visual by date range and other visual by x months relativ to end of date range.

I have two visuals on my page and date range (Timeline) selector.

 

I want the first (1.) to be filtered exactly by the selected range. This already works as expected.

The second on (2.) should be filtered by the last date of the selected range and starting 12 Months earlier.

For example if I select the months Jan and Feb of 2021, the first visual (1.) should show data filtered by 01.01.2021-28.02.2021 and the second visual (2.) from 01.03.2020-28.02.2021.

 

JonasMarty_0-1618823827570.png

 

How can i achieve this behavior?

 

I already have a CalendarTable generated as following where I could add other fields if needed:

JonasMarty_1-1618824199508.png

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @JonasMarty ,

 

Since the interaction between the slicer and the visualizations makes your information being filtered by the value on the slicer. 

 

In this case you need to create some minor changes in your model.

 

In my example I have added a YEARMONTH column to my model but you can add two columns one to year and another of month with the following syntax:

YearMonth = RELATED (CalendarTable[YearMonth])

 

Add the following measure:

Previous 12 Months = 
CALCULATE (
SUM('Table'[Value]),
    DATESINPERIOD ('Calendar'[Date], MAX ( 'Calendar'[Date] ), -12, MONTH )
)

Now the setup of your model must be in the following way:

  • Slicer - Based on the calendar table
  • Table - Based on the calendar table
  • Bar chart - X-axis based on the columns created with the related formula

Result below and in attach PBIX file:

MFelix_0-1618911532432.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @JonasMarty ,

 

Since the interaction between the slicer and the visualizations makes your information being filtered by the value on the slicer. 

 

In this case you need to create some minor changes in your model.

 

In my example I have added a YEARMONTH column to my model but you can add two columns one to year and another of month with the following syntax:

YearMonth = RELATED (CalendarTable[YearMonth])

 

Add the following measure:

Previous 12 Months = 
CALCULATE (
SUM('Table'[Value]),
    DATESINPERIOD ('Calendar'[Date], MAX ( 'Calendar'[Date] ), -12, MONTH )
)

Now the setup of your model must be in the following way:

  • Slicer - Based on the calendar table
  • Table - Based on the calendar table
  • Bar chart - X-axis based on the columns created with the related formula

Result below and in attach PBIX file:

MFelix_0-1618911532432.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.