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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Highlight rows from last x days based on slicer

Hi

 

I'm new to Power Bi and have a question concerning slicing and relative dates. 

So i have a table, that records actions taken in a system, based on categories and aggregated by date.

DateCategoryAmount
01/01/2020A5
22/01/2020B10

 

 

Now I'm using a date slicer, so that i can look at my data in a monthly, or yearly fashion. 

 

And now i would like to see, which category has had the most amount of actions in the last x days of the period, that i'm currently looking at. 

My first intuition, was to calculate a new column, that shows me, if the date is within my set period (lets use a week, so 7 days as an example)

So with a new column calculated like this :

 

 

 

Within_last_7_days = 'data'[Date] >= MAX('data'[Date])-7

 

 

 

My data would look like this: 

DateCategoryAmountWithin_last_7_days
01/01/2020A5False
22/01/2020B10True

Which would be exactly what i want:

SaschaDS_0-1623838212917.png

Exept for the small problem, that columns are not dynamically recalculated based on the slicer. 
So this only works for the last month in my dataset and not for any other selection. 

 

How can I achive this with a dynamic solution?

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

It should be noted that the column is static and can be used as a legend field, and measure is dynamically changed based on the current row context and cannot be used as a legend field.

In addition, based on your description, you could use the category as a legend and apply the created measure in the visual level filter.

Vlianlmsft_0-1623998610574.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

It should be noted that the column is static and can be used as a legend field, and measure is dynamically changed based on the current row context and cannot be used as a legend field.

In addition, based on your description, you could use the category as a legend and apply the created measure in the visual level filter.

Vlianlmsft_0-1623998610574.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Try a measure like

Within_last_7_days =
var _1 MAXX(allsellected('data'), 'data'[Date])-7
return
if( max('data'[Date]) >=_1, true(), false() )

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak I must be doing something wrong. The code that i'm using is what you suggested:

 

Within_last_7_days = 
var _1= MAXX(ALLSELECTED(data),  data[Date])-7
return
if( max(data[Date]) >=_1, true(), false() )

 

 

But the result, if i plot it as a table is this:

SaschaDS_0-1623852101600.png

And i can not add it as anything other, then a tooltip for my visualization, whereas i'd want it to be a legend. 

SaschaDS_1-1623852192132.png

 

Anonymous
Not applicable

Although it does work with a table. (The whole of april is selected in this case)

SaschaDS_1-1623855943160.png

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.