Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hey Community,
TLDR: Given monthly data of past few years, how can I create a relative month filter, where I have the option to filter data of last X month (where my reference month is not today, bu the latest data available)?
I have monthly data of generation starting 2016, and as of now the latest data is of May 2023 (which keeps on getting updated as we move ahead).
I'm trying to visualize total generation value for last X month, where user has option to select the X. Considering right now, I have data till May 2023, my last month would be May 2023.
The by default relative date slicer in Power BI considers last day as today , and hence, I'm not getting the desired result.
As you can see, the relative date is considering today as the benchline, plus since I have only monthly data, the option of 'weeks' and 'days' do not make sense for my visualization.
I need something like this:
Just a dropdown of a number of months, and based on that, my generation graph automatically adjusts.
To create a relative month filter, I tried the following approach.
Disconnected_Date = CALENDAR(FIRSTDATE('Actual Date'[Date]),LASTDATE('Actual Date'[Date]))Selected_date = SELECTEDVALUE(Disconnected_Date[Date])
Then I created a table for number of months.
Selected_Period = SELECTEDVALUE(Month_table[Months])
And finally, I created this filter.
Date_filter =
var _selected =[Selected_date]
var _date=min('Actual Date'[Date])
var _period= [Selected_Period]*30
var _daterange=_selected-_period
var _filter=if(_date<=_selected,if(_date>=_daterange,1,0),0)
return
_filter
The above filter works on days perfectly fine, but for months, I had to multiply it by 30. So, I'm getting correct results for 7 months, but after that, if I select 8 months, I am getting 7-month values. I believe multiplying it by 30 is not the best option.
I wanted to know how I can use the above filter on month level rather than on days level?
The standard approach is similar to
- create a string representation of your date column, replace the latest date with a string "Latest"
- sort that new column by the original date column
- add a slicer or visual/page/report level filter
- set the filter to "Latest"
- publish the pbix to the workspace/app
Hi,
Share some data to work with.
@adiljamal , do all calculation based on date
Like last 5 days, use your period variable
//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = _max -5
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))
Last 12 months
//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = eomonth(_max, -12) +1
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))
you can use date as date add
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 44 | |
| 43 | |
| 38 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 68 | |
| 64 | |
| 31 | |
| 29 | |
| 24 |