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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
nataliesmiy1357
Helper IV
Helper IV

Date Filter Dax

Hello!  I created a dax formula that is the following:

 

Date Range Filter =
VAR TodayDate = TODAY()
VAR Past3Months = EDATE(TodayDate, -3)
VAR Past6Months = EDATE(TodayDate, -6)
VAR Past12Months = EDATE(TodayDate, -12)
RETURN
SWITCH(
    TRUE(),
    'Date'[Date] >= Past3Months, "Past 3 Months",
    'Date'[Date] >= Past6Months, "Past 6 Months",
    'Date'[Date] >= Past12Months, "Past 12 Months",
    "All Data"
)
 
But I want to make sure that the past 6 months inlcludes that data, but also the past 3 months (so it's kinda cumulative)
 
How is this possible?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you lbendlin and Shravan133 

Hi, @nataliesmiy1357 

When you use >=, your switch function should look like this:

SWITCH(
    TRUE(),
    'Date'[Date] >= Past12Months, "Past12Months",
    'Date'[Date] >= Past6Months, "Past 6 Months",
    'Date'[Date] >= Past3Months, "Past3Months",
    "All Data"
)

Or when you use <=, your switch function should look like this:

SWITCH(
    TRUE(),
    'Date'[Date] <= Past3Months, "Past3Months",
    'Date'[Date] <= Past6Months, "Past 6 Months",
    'Date'[Date] <= Past12Months, "Past12Months",
    "All Data"
)

Let me use the following example to show you why:

Measure 2 = SWITCH(TRUE(),
 SUM('Table'[Value])<=190,"A",
 SUM('Table'[Value])<=150,"B",
 SUM('Table'[Value])<=90,"C"
)

vjianpengmsft_0-1726818538331.png

In my case 94 is less than 190 and 150, and its correct level should be B. However, since the switch ends the judgment when the first condition is met, then the line corresponding to 94 is judged to be A.

When I change it to something like this, I get the correct output.

Measure 2 = SWITCH(TRUE(),
 SUM('Table'[Value])<=90,"A",
 SUM('Table'[Value])<=150,"B",
 SUM('Table'[Value])<=190,"C"
)

vjianpengmsft_1-1726818884569.png

I've provided the PBIX file used this time below.

 

 

 

Best Regards

Jianpeng Li

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

7 REPLIES 7
Anonymous
Not applicable

Thank you lbendlin and Shravan133 

Hi, @nataliesmiy1357 

When you use >=, your switch function should look like this:

SWITCH(
    TRUE(),
    'Date'[Date] >= Past12Months, "Past12Months",
    'Date'[Date] >= Past6Months, "Past 6 Months",
    'Date'[Date] >= Past3Months, "Past3Months",
    "All Data"
)

Or when you use <=, your switch function should look like this:

SWITCH(
    TRUE(),
    'Date'[Date] <= Past3Months, "Past3Months",
    'Date'[Date] <= Past6Months, "Past 6 Months",
    'Date'[Date] <= Past12Months, "Past12Months",
    "All Data"
)

Let me use the following example to show you why:

Measure 2 = SWITCH(TRUE(),
 SUM('Table'[Value])<=190,"A",
 SUM('Table'[Value])<=150,"B",
 SUM('Table'[Value])<=90,"C"
)

vjianpengmsft_0-1726818538331.png

In my case 94 is less than 190 and 150, and its correct level should be B. However, since the switch ends the judgment when the first condition is met, then the line corresponding to 94 is judged to be A.

When I change it to something like this, I get the correct output.

Measure 2 = SWITCH(TRUE(),
 SUM('Table'[Value])<=90,"A",
 SUM('Table'[Value])<=150,"B",
 SUM('Table'[Value])<=190,"C"
)

vjianpengmsft_1-1726818884569.png

I've provided the PBIX file used this time below.

 

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Change the order of the checks, list them the other way round. SWITCH will exit after the first match.

When I switch them - I am still only getting one grouping.  I want to make sure when I do:

3 months data = 3 months

6 months = 3 months and 3 more months

12 months = 6 months and 6 more months.

 

Date Range Filter =
VAR TodayDate = TODAY()
VAR Past3Months = EDATE(TodayDate, -3)
VAR Past6Months = EDATE(TodayDate, -6)
VAR Past12Months = EDATE(TodayDate, -12)
RETURN

SWITCH(
    TRUE(),
    'OR Report'[DATE].[Date] <= Past12Months, "Last 12 Months",
    'OR Report'[DATE].[Date] <= Past6Months, "Last 06 Months",
    'OR Report'[DATE].[Date] <= Past3Months, "Last 03 Months",
    "All Data"

)

 

No, you will only ever get a scalar value (single result) out of a SWITCH statement.

So how would I code it without a switch?

You would add these flags to your calendar table.

Shravan133
Super User
Super User

try this: 

Date Range Filter =
VAR TodayDate = TODAY()
VAR Past3Months = EDATE(TodayDate, -3)
VAR Past6Months = EDATE(TodayDate, -6)
VAR Past12Months = EDATE(TodayDate, -12)
RETURN
SWITCH(
TRUE(),
'Date'[Date] >= Past3Months, "Past 3 Months",
'Date'[Date] >= Past6Months && 'Date'[Date] < Past3Months, "Past 6 Months (including Past 3 Months)",
'Date'[Date] >= Past12Months && 'Date'[Date] < Past6Months, "Past 12 Months (including Past 6 and 3 Months)",
"All Data"
)

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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