Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi All,
New to Power BI and struggling with creating slicer to filter on custom time periods into the future. Sample data is below.
Project | Function | Code | Month | Hours | Months Diff |
A1 | AP | KKAP | 6/1/2021 | 15 | 1 |
A1 | AP | KKAP | 7/1/2021 | 15 | 2 |
A1 | AP | KKAP | 8/1/2021 | 15 | 3 |
A1 | AP | KKAP | 9/1/2021 | 15 | 4 |
A1 | AP | KLAP | 6/1/2021 | 10 | 1 |
A1 | AP | KLAP | 7/1/2021 | 10 | 2 |
A1 | AP | KLAP | 8/1/2021 | 10 | 3 |
A1 | AP | KLAP | 9/1/2021 | 10 | 4 |
A1 | AQ | KMAQ | 6/1/2021 | 1 | 1 |
A1 | AQ | KMAQ | 7/1/2021 | 1 | 2 |
A1 | AQ | KMAQ | 8/1/2021 | 1 | 3 |
A1 | AQ | KMAQ | 9/1/2021 | 1 | 4 |
A2 | AP | KKAP | 6/1/2021 | 40 | 1 |
A2 | AP | KKAP | 7/1/2021 | 40 | 2 |
A2 | AP | KLAP | 6/1/2021 | 10 | 1 |
A2 | AP | KLAP | 7/1/2021 | 10 | 2 |
A2 | AQ | KMAQ | 6/1/2021 | 1 | 1 |
A2 | AQ | KMAQ | 7/1/2021 | 1 | 2 |
I created Time Period Table with slicer options:
Time Period Slicer |
Next 2 Months |
All Months |
Then created Time Period Filter and applied to my visual, setting equal to "Y":
Solved! Go to Solution.
@Anonymous , I think you should try measure like this example
//used date table
Measure =
var _max = maxx(allselected('Date'), Date[Date])
var _min = eomonth(_max,-3)+1
var _sel = 'Time Period'[Time Period Slicer])
return
Switch(True() ,
_sel = ="Next 2 Months",calculate(Sum(Table[total hours]), filter('Date', 'Date'[Date] >= Min && ' Date'[Date] <= _max)),
_sel = ="All Months",calculate(Sum(Table[total hours]))
)
or
Measure =
var _max = maxx(allselected('Date'), Date[Date])
var _min = eomonth(_max,-3)+1
var _sel = 'Time Period'[Time Period Slicer])
return
Switch(True() ,
_sel = ="Next 2 Months",calculate(Sum(Table[total hours]), filter(all('Date'), 'Date'[Date] >= Min && ' Date'[Date] <= _max)),
_sel = ="All Months",calculate(Sum(Table[total hours]),all('Date'))
)
if needed refer
Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI
@Anonymous , I think you should try measure like this example
//used date table
Measure =
var _max = maxx(allselected('Date'), Date[Date])
var _min = eomonth(_max,-3)+1
var _sel = 'Time Period'[Time Period Slicer])
return
Switch(True() ,
_sel = ="Next 2 Months",calculate(Sum(Table[total hours]), filter('Date', 'Date'[Date] >= Min && ' Date'[Date] <= _max)),
_sel = ="All Months",calculate(Sum(Table[total hours]))
)
or
Measure =
var _max = maxx(allselected('Date'), Date[Date])
var _min = eomonth(_max,-3)+1
var _sel = 'Time Period'[Time Period Slicer])
return
Switch(True() ,
_sel = ="Next 2 Months",calculate(Sum(Table[total hours]), filter(all('Date'), 'Date'[Date] >= Min && ' Date'[Date] <= _max)),
_sel = ="All Months",calculate(Sum(Table[total hours]),all('Date'))
)
if needed refer
Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI
Thank you so much! I was able to use the syntax of FILTER within CALCULATE which you suggested to get this to work:
Hours =
IF('Time Period'[Time Period]="Next 2 Months",
calculate(Sum('Data'[Hours]), filter('Data', 'Data'[Months Diff] >= 1 && 'Data'[Months Diff] <= 2)),
calculate(Sum('Data'[Hours])))
Thanks again!
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
68 | |
57 | |
55 | |
36 | |
34 |
User | Count |
---|---|
76 | |
73 | |
48 | |
45 | |
43 |