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.
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.
Date | Category | Amount |
01/01/2020 | A | 5 |
22/01/2020 | B | 10 |
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:
Date | Category | Amount | Within_last_7_days |
01/01/2020 | A | 5 | False |
22/01/2020 | B | 10 | True |
Which would be exactly what i want:
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?
Solved! Go to Solution.
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.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@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() )
@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:
And i can not add it as anything other, then a tooltip for my visualization, whereas i'd want it to be a legend.
Although it does work with a table. (The whole of april is selected in this case)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |