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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Prathyusika
Frequent Visitor

please help in converting SQL query to Power Bi dax function - cal column

 case when [ClosedDate] >= WM_START_DATE and
            
            [ClosedDate] <= DATEADD(day,90,WM_START_DATE) and GETDATE() >= WM_START_DATE then '90 Days'
 
          -- when[ClosedDate] >= [WM_START_DATE] and [ClosedDate] <= DATEADD(day,90,[WM_START_DATE]) and GETDATE() >= DATEADD(day,90,[WM_START_DATE]) then '90 Days'
             
            -- when [ClosedDate] >= prod_date and [ClosedDate] <= DATEADD(day,180,prod_date) and GETDATE() >= DATEADD----(day,180,prod_date) then '180 Days'
             when [ClosedDate] > dateadd(day,90 ,WM_START_DATE) and [ClosedDate] <= DATEADD(day,180,WM_START_DATE) and GETDATE() >= DATEADD(day,90,WM_START_DATE) then '180 Days'
             when [ClosedDate] > dateadd(day,180,WM_START_DATE) and [ClosedDate] <= DATEADD(day,270,WM_START_DATE) and GETDATE() >= DATEADD(day,180,prod_date) then '270 Days'    
             when [ClosedDate] > dateadd(day,270,WM_START_DATE) and [ClosedDate] <= DATEADD(day,360,WM_START_DATE) and GETDATE() >= DATEADD(day,270,WM_START_DATE) then '360 Days'
else 'Greater than 360 days'
             end as [Time Bucket]
1 ACCEPTED SOLUTION
AjithPrasath
Resolver II
Resolver II

Hi @Prathyusika ,

 

Please try the below code:

 

Time Bucket = 
    SWITCH(
        TRUE(),
        [ClosedDate] >= WM_START_DATE &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 90, DAY) &&
        TODAY() >= WM_START_DATE, "90 Days",
        
        [ClosedDate] > DATEADD(WM_START_DATE, 90, DAY) &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 180, DAY) &&
        TODAY() >= DATEADD(WM_START_DATE, 90, DAY), "180 Days",
        
        [ClosedDate] > DATEADD(WM_START_DATE, 180, DAY) &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 270, DAY) &&
        TODAY() >= DATEADD(WM_START_DATE, 180, DAY), "270 Days",
        
        [ClosedDate] > DATEADD(WM_START_DATE, 270, DAY) &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 360, DAY) &&
        TODAY() >= DATEADD(WM_START_DATE, 270, DAY), "360 Days",
        
        TRUE(), "Greater than 360 days"
    )

 

 

Best Regards,

Ajith Prasath

 

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

View solution in original post

2 REPLIES 2
grazitti_sapna
Super User
Super User

Hey, You can achieve this by 

Time Bucket =

VAR WM_START_DATE = 'YourTableName'[WM_START_DATE]

VAR ClosedDate = 'YourTableName'[ClosedDate]

VAR Today = TODAY()

RETURN

IF(

ClosedDate >= WM_START_DATE &&

ClosedDate <= DATEADD(WM_START_DATE, 90, DAY) &&

Today >= WM_START_DATE,

"90 Days",

IF(

ClosedDate > DATEADD(WM_START_DATE, 90, DAY) &&

ClosedDate <= DATEADD(WM_START_DATE, 180, DAY) &&

Today >= DATEADD(WM_START_DATE, 90, DAY),

"180 Days",

IF(

ClosedDate > DATEADD(WM_START_DATE, 180, DAY) &&

ClosedDate <= DATEADD(WM_START_DATE, 270, DAY) &&

Today >= DATEADD(WM_START_DATE, 180, DAY),

"270 Days",

IF(

ClosedDate > DATEADD(WM_START_DATE, 270, DAY) &&

ClosedDate <= DATEADD(WM_START_DATE, 360, DAY) &&

Today >= DATEADD(WM_START_DATE, 270, DAY),

"360 Days",

"Greater than 360 days"

)

)

)

)

Thank you

AjithPrasath
Resolver II
Resolver II

Hi @Prathyusika ,

 

Please try the below code:

 

Time Bucket = 
    SWITCH(
        TRUE(),
        [ClosedDate] >= WM_START_DATE &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 90, DAY) &&
        TODAY() >= WM_START_DATE, "90 Days",
        
        [ClosedDate] > DATEADD(WM_START_DATE, 90, DAY) &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 180, DAY) &&
        TODAY() >= DATEADD(WM_START_DATE, 90, DAY), "180 Days",
        
        [ClosedDate] > DATEADD(WM_START_DATE, 180, DAY) &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 270, DAY) &&
        TODAY() >= DATEADD(WM_START_DATE, 180, DAY), "270 Days",
        
        [ClosedDate] > DATEADD(WM_START_DATE, 270, DAY) &&
        [ClosedDate] <= DATEADD(WM_START_DATE, 360, DAY) &&
        TODAY() >= DATEADD(WM_START_DATE, 270, DAY), "360 Days",
        
        TRUE(), "Greater than 360 days"
    )

 

 

Best Regards,

Ajith Prasath

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.