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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
adoster
Resolver I
Resolver I

DAX SWITCH statement with && to pull values in last 365 days

Hello,

I am trying to build a DAX statement that includes an && statement to only include values within the last 365 days.

 

This statement works (without the 365)

TEST1 = SWITCH (
TRUE(),
'TABLE1'[STATUS] = "OPEN", RELATED ('TABLE2'[OPENVALUE]),
'TABLE1'[STATUS] = "CLOSED", RELATED ('TABLE2'[CLOSEDVALUE]),
BLANK()
)
 
I am trying to add code so that if the STATUS is OPEN && is in the last 365 days THEN OPENVALUE
TEST2 = SWITCH (
TRUE(),
'TABLE1'[STATUS] = "OPEN" && DATEINLAST365DAYS, RELATED ('TABLE2'[OPENVALUE]),
'TABLE1'[STATUS] = "CLOSED", RELATED ('TABLE2'[CLOSEDVALUE]),
BLANK()
)
 
appreciate any assistance.
Thanks!
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @adoster 

try like:

TEST2 = 
SWITCH (
    TRUE(),
    'TABLE1'[STATUS] = "OPEN" 
     && DATEDIFF(TABLE1[Date], TODAY(), DAY)<=365
     RELATED ('TABLE2'[OPENVALUE]),
     'TABLE1'[STATUS] = "CLOSED", 
     RELATED ('TABLE2'[CLOSEDVALUE]),
BLANK()
)
 
add the DATEDIFF part to the closed part if needed.

View solution in original post

1 REPLY 1
FreemanZ
Super User
Super User

hi @adoster 

try like:

TEST2 = 
SWITCH (
    TRUE(),
    'TABLE1'[STATUS] = "OPEN" 
     && DATEDIFF(TABLE1[Date], TODAY(), DAY)<=365
     RELATED ('TABLE2'[OPENVALUE]),
     'TABLE1'[STATUS] = "CLOSED", 
     RELATED ('TABLE2'[CLOSEDVALUE]),
BLANK()
)
 
add the DATEDIFF part to the closed part if needed.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.