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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
andres6and8
Frequent Visitor

How can I create inclusive time period categories with Dax/PowerBI?

I have a data set in Power BI where there's a date column. I'd like to filter the dates along the following criteria: past 30 days, past 60 days, past 90 days, and all time.

 

I added three custom columns, each with binary values: `is_past_30`, `is_past_60`, and `is_past_90`. I then created a calculation called `Time Frame` and set it to the following:

 

Time Frame = IF(
        Query1[is_past_30]+Query1[is_past_60]+Query1[is_past_90] < 1, "4. All time"
        , IF(
            Query1[is_past_30]+Query1[is_past_60]+Query1[is_past_90] < 2, "3. Past 90 Days"
            , IF(
                Query1[is_past_30]+Query1[is_past_60]+Query1[is_past_90] < 3, "2. Past 60 Days"
                , IF(
                    Query1[is_past_30]+Query1[is_past_60]+Query1[is_past_90] < 4, "1. Past 30 Days"
                    , "n/a"
    				)
                )
            )
        )

 

This code works if I want to slice the time periods exclusively- i.e., past 60 days but NOT in the past 30 days. However, by "Last 60 Days" I'd like to include the last 60, too. Under this scheme, probably because of the "IF-THEN" statement, that is not possible when placing the options in a slicer.

Does anyone have a suggestion for a workaround?

 

2 ACCEPTED SOLUTIONS
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @andres6and8

 

Here is one option that uses Measure tables.  The link to a PBIX file is here

 

https://1drv.ms/u/s!AtDlC2rep7a-jlM8zvxEyg6XK2MB

 

Bascially you can add your own date ranges to the table called Date Ranges and these will automatically appear in your slicers.

 

Use the tab called All Sorts to see what I mean.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

@andres6and8

 

In @Phil_Seamark's pbix, it contains a "Days From Today" column. 

 

4.PNG

 

This columns is used to compare with "days" (which is ID in Date Range table) for calculation.

 

3.PNG

 

66.PNG

 

You can also refer to blog below for this kind of "Last X period" requirement:

 

Power BI – Time Period Slicer for Last 7 Days,Last 30 Days..

 

Regards,

 

View solution in original post

4 REPLIES 4
philibin
New Member

If I am understanding your question... I accomplished the same with this calculated column:

 

let
vnow = Date.From(DateTime.LocalNow())
in
if [Date] = vnow then "TODAY"
else if Date.WeekOfYear([Date]) = Date.WeekOfYear(vnow)
and Date.Year([Date]) = Date.Year(vnow) then "THIS WEEK"
else if Date.ToText([Date], "MM yyyy") = Date.ToText(vnow, "MM yyyy") then "THIS MONTH"
else if Date.QuarterOfYear([Date]) = Date.QuarterOfYear(vnow)
and Date.Year([Date]) = Date.Year(vnow) then "THIS QUARTER"
else if Date.IsInYearToDate([Date]) then "THIS YEAR"
else if Duration.Days(vnow - [Date]) <= 365 then "IN YEAR"
else "ALL TIME"

 

where the date column I am looking at is called [Date] and I wanted to know if the row is today, in the last week, in the last month, etc...

 

Then from there I used a table for each group, then appended them all together. It is clunky but works.

Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @andres6and8

 

Here is one option that uses Measure tables.  The link to a PBIX file is here

 

https://1drv.ms/u/s!AtDlC2rep7a-jlM8zvxEyg6XK2MB

 

Bascially you can add your own date ranges to the table called Date Ranges and these will automatically appear in your slicers.

 

Use the tab called All Sorts to see what I mean.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

@Phil_Seamark

 

Thank you for the example. This is definitely what I'd like to implement, but beside creating a reference table with ID and Time Frame, I'm really not sure how to implement everything else. Could you provide a little more explanation?

 

Thank you in advance!

@andres6and8

 

In @Phil_Seamark's pbix, it contains a "Days From Today" column. 

 

4.PNG

 

This columns is used to compare with "days" (which is ID in Date Range table) for calculation.

 

3.PNG

 

66.PNG

 

You can also refer to blog below for this kind of "Last X period" requirement:

 

Power BI – Time Period Slicer for Last 7 Days,Last 30 Days..

 

Regards,

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors