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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Ash10
Regular Visitor

Need help on dynamic interactions

Hi, 

 

I have a table visual which has a timestamp column and a line chart with same timestamp column in X axis.

Now when I/end user click on any time stamp value I need the line chart to display last 5 days and next 5 days values and dynamicaly changes based on selected timestamp value. 

 

I tried created two measures as last5Day = selectedvalue('table'[timestamp]) - 5 and next5Day = selectedvalue('table'[timestamp]) + 5, now I tried adding these two measures in minimum and maximum X axis vales in visualization pane, but it is not working. 

If any leads please let me know. Thanks in Advance

8 REPLIES 8
DataNinja777
Super User
Super User

Hi @Ash10 ,

 

You can create a measure that dynamically calculates whether a timestamp falls within the 5-day range before or after the selected timestamp.

WithinRange = 
VAR SelectedDate = SELECTEDVALUE('table'[timestamp])
VAR StartDate = SelectedDate - 5
VAR EndDate = SelectedDate + 5
RETURN
    IF(
        'table'[timestamp] >= StartDate &&
        'table'[timestamp] <= EndDate,
        1, 0
    )

Next, in the line chart, add this WithinRange measure to the visual-level filter. Set the filter condition to show values where WithinRange = 1.

 

Then, set up interaction between the table and the line chart by using the Visual Interactions tool in Power BI. This will ensure that when a user clicks on a timestamp in the table, it dynamically updates the line chart.

 

Calculated columns would result in static values, whereas using a measure provides dynamic filtering that updates the line chart based on user interactions. This is why using a measure is preferred for this task.

sorry, this is not working, when I set up interaction between the table and the line chart by using the Visual Interactions tool in Power BI the line chart is filtered to one value, this is because my X axis is timestamp

 

Selva-Salimi
Super User
Super User

Hi @Ash10 

 

you should use a measure to calculate the Y-axis value. you can write the measure as follows : (lets assume thatyou have sales data)

 

measure sales_in range := calcualte (sum(sales) , filter (all(table) , timestamp>= selectedvalue(timestamp) - 5 &&  timestamp<= selectedvalue(timestamp) + 5)

 

If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly. 

Hi Thank you for your solution, Unfortunately it is not working :(.

Ash10
Regular Visitor

when I select only one timestamp due to interaction it is filtering to only one point in line chart, if I block interaction it is not working

 

@Ash10 

 

you should have a Dimdate table and selected timestamp slicer, should be added to this report using DimDate

Hi @Selva-Salimi, Thank you for the reply, how can we accomplish this?

you can create a table with minimum date and maximum date you need to have as follows:

SelvaSalimi_1-1726650957649.png

 

 

then go to transform data (edit query) and add a custom column using the following formula:

{Number.From([start date])..Number.From([end date])}

 then click on the specified list and expand. this can call your DimDate table.

SelvaSalimi_2-1726651104613.png

 

 

 

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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