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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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() )

 

 

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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