Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

switch using date ranges

I have a DATE table with the following columns
Date (DATE format), (the following columns are all Whole Numbers) WeekNum, Month, Day, Year, Qtr, End Date (DATE format), SprintNumber (whole number) (this is a calculated column I'm using the SWITCH function in)

 

I'm trying to put a number from 1-8 in this SprintNumber column

 

SprintNumber 1 = dates between 8/1/2019 and 10/31/2019

SprintNumber 2 = dates between 11/1/2019 and 1/31/2020

SprintNumber 3 = dates between 2/1/2020 and 4/31/2020

SprintNumber 4,5,6,7,8 every 3 months following sprint3

 

I have the following formula and don't know what I'm doing wrong (I only have the first 3 sprints, but would add 4-8)

SprintNumber = SWITCH(
'Date Table'[Date] >= DATE(2019,8,1),1,
'Date Table'[Date] >= DATE(2019,11,1),2,
'Date Table'[Date] >= DATE(2020,1,1),3)
 
I have also tried - but this didn't work either

 

 
I have tried using DATESBETWEEN etc. and other variations, but can't figure this out. 
 
Thanks in advance ! 
Jim

 

12 Replies

  • Anonymous , Formula seems fine. The only doubt I have is that either Month of year is of data type text.

     

    Can you share a sample pbix after removing sensitive data?

    • Anonymous's avatar
      Anonymous
      Not applicable

      I can't send the pbix. However here is a screen shot - YEAR is the same type. 

      I have also tried this 

       

       

       

    • Anonymous's avatar
      Anonymous
      Not applicable

      Here is the DATE table - how I created it. 

       

       

    • Anonymous's avatar
      Anonymous
      Not applicable

      I didn't get any errors using this (I changed the way the calendar table was created - using 

      Date Table = CALENDAR(Date (2018, 1, 1), DATE( 2022, 12, 31))
       
      Then I used this method: BUT I didn't get ANY results. 

       

       

  • Geradav's avatar
    Geradav
    Responsive Resident

    Anonymous The FORMAT() function "Converts a value to text according to the specified format." (Source FORMAT function (DAX) - DAX | Microsoft Docs)

    Therefore you would be comparing a number to a text data type.
    Also, passing a number as text data type as argument to the VALUE() function is the same as just writing a literal number.

    I agree with amitchandak  that if you have some sample PBIX that you can share with us, it would help in the process of helping you.

     

    David

    • Anonymous's avatar
      Anonymous
      Not applicable

      Geradav Thanks for your help on this. Please see my most recent update. I have cleaned up the function. But I'm not getting the results for sprintnumber 2, or 4. 

       

      Thanks in advance,

      Jim