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! Request now

Reply
bocciawinsocial
New Member

case when with between two dates - HOW TO USE IN DAX?

Hello guys, I have this case when with between two dates, how can I do this in dax? Can someone help me?

            WHEN DATE(leads.created_at) between '2020-01-01' and '2020-02-29' THEN '1ªB'
            WHEN DATE(leads.created_at) between '2020-03-01' and '2020-04-30' THEN '2ªB'
            WHEN DATE(leads.created_at) between '2020-05-01' and '2020-06-30' THEN '3ªB'
            WHEN DATE(leads.created_at) between '2020-07-01' and '2020-08-31' THEN '4ªB'
            WHEN DATE(leads.created_at) between '2020-09-01' and '2020-10-31' THEN '5ªB'
            WHEN DATE(leads.created_at) between '2020-11-01' and '2020-12-31' THEN '6ªB'
            WHEN DATE(leads.created_at) between '2019-01-01' and '2019-02-28' THEN '1ªB'
            WHEN DATE(leads.created_at) between '2019-03-01' and '2019-04-30' THEN '2ªB'
            WHEN DATE(leads.created_at) between '2019-05-01' and '2019-06-30' THEN '3ªB'
            WHEN DATE(leads.created_at) between '2019-07-01' and '2019-08-31' THEN '4ªB'
            WHEN DATE(leads.created_at) between '2019-09-01' and '2019-10-31' THEN '5ªB'
            WHEN DATE(leads.created_at) between '2019-11-01' and '2019-12-31' THEN '6ªB'
            WHEN DATE(leads.created_at) between '2021-01-01' and '2021-02-28' THEN '1ªB'
            WHEN DATE(leads.created_at) between '2021-03-01' and '2021-04-30' THEN '2ªB'
            WHEN DATE(leads.created_at) between '2021-05-01' and '2021-06-30' THEN '3ªB'
            WHEN DATE(leads.created_at) between '2021-07-01' and '2021-08-31' THEN '4ªB'
            WHEN DATE(leads.created_at) between '2021-09-01' and '2021-10-31' THEN '5ªB'
            WHEN DATE(leads.created_at) between '2021-11-01' and '2021-12-31' THEN '6ªB'
            ELSE null end as 'bimestre',

1 ACCEPTED SOLUTION
timg
Solution Sage
Solution Sage

Here's a reference and a sample. This should do if you expand it with the other categories and appropriate result values:

Test = 
SWITCH(TRUE(),
   dimDate[Date]>=DATE(2020,01,01) && dimDate[Date]<DATE(2020,02,29),"1ªB",
   "N/A")

 

 1test.PNG

 

Best regards,

 

Tim





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

5 REPLIES 5
smpa01
Super User
Super User

@bocciawinsociallike this

SWITCH(TRUE(),
     DATE(leads.created_at) >= '2020-01-01' && DATE(leads.created_at) <='2020-02-29', '1ªB',            
     DATE(leads.created_at) >= '2020-03-01' && DATE(leads.created_at) <='2020-04-30', '2ªB',
     .....................................................................................)
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
timg
Solution Sage
Solution Sage

Here's a reference and a sample. This should do if you expand it with the other categories and appropriate result values:

Test = 
SWITCH(TRUE(),
   dimDate[Date]>=DATE(2020,01,01) && dimDate[Date]<DATE(2020,02,29),"1ªB",
   "N/A")

 

 1test.PNG

 

Best regards,

 

Tim





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks @timg,

do you know how to solve this: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

Hi @bocciawinsocial,

Could you check if you are refering to the datecolumn or the date table in your code? The spots where I mention dimDate[Date] refer to the specific date column within the table. if you only mention the table (for example 'dimDate') this may cause the error, since there are multiple columns within the table. 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Pragati11
Super User
Super User

Hi @bocciawinsocial ,

 

You can try writing a measure using DAX with SWITCH function. Refer an example in the following:

https://radacad.com/write-conditional-statement-using-switch-in-dax-and-power-bi

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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