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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Jan_Trummel
Helper IV
Helper IV

Dynamic filter by slicer

Hello to the forum,

 

I have a question.

 

1) My data


I have the Orders and Calendar tables in Power BI Desktop. Both are linked by a 1-n relationship:

My data modelMy data model

In the Orders table I have the following data:

Table "Orders"Table "Orders"

 

2) My report (how it should be)

 

I want to generate the following report:


In a slicer, the user selects a specific date. In a further slicer, he can then set how many days he would like to look into the past, starting from the selected date. (Here I use a numeric parameter.)


Here is an example:

If the user selects 04/10/2023 and wants to look 7 days into the past, then the line chart should show:

An example reportAn example report

In the line chart, the days 03.04. – 04/10/2023 are displayed.
(In the example, I filtered the diagram by hand.)

 

Does anyone have an idea how I can implement this?

 

Greetings

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Jan_Trummel Try something below. Note, assumes disconnected tables for slicers. PBIX is attached below signature.

Measure = 
    VAR __Date = MAX('Dates'[Date])
    VAR __DaysBack = [Parameter Value]
    VAR __OrderDate = MAX('Orders'[Order date])
    VAR __Result = IF(__OrderDate <= __Date && __OrderDate >= __Date - __DaysBack, SUM('Orders'[Sales]), BLANK())
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Jan_Trummel
Helper IV
Helper IV

@Greg_Deckler It works great, thank you very much!

Greg_Deckler
Super User
Super User

@Jan_Trummel Try something below. Note, assumes disconnected tables for slicers. PBIX is attached below signature.

Measure = 
    VAR __Date = MAX('Dates'[Date])
    VAR __DaysBack = [Parameter Value]
    VAR __OrderDate = MAX('Orders'[Order date])
    VAR __Result = IF(__OrderDate <= __Date && __OrderDate >= __Date - __DaysBack, SUM('Orders'[Sales]), BLANK())
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi, @Greg_Deckler do you think there is a solution where the Calendar table can stay connected to the Orders table?

 

This would be exactley what I need.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.