Forum Discussion

UK_User123456's avatar
UK_User123456
Resolver I
7 years ago
Solved

Returning text based on difference

Hi All,

 

Is there a way of returning text based on a number that I have got e.g. the difference between date(s)?

 

e.g. 

Date 1Date 2Date DifferenceText
01/01/201901/06/2019151Exisiting
12/05/201901/07/201950New
01/06/201831/10/2018152Old

 

I have tried nested if statements but all I get is that for every customer we have it displays the same text for every date we have, I just want it to return the text based on the records I need. 

 

TIA

  • Hi UK_User123456 

     

    create a column:

     

    date diference = DATEDIFF(date1;date2;DAY)  (use semicolon or comma)
     
    create another column:
    text result = If (date diference <= 50;"New";date diference <= 150;"Existing";"Old")
     
    best regards.

8 Replies

  • Based on your example and assuming [Date Difference] is a measure this should work.

    Text =
    SWITCH(
        TRUE(),
        [Date Difference] = 151, "Existing",
        [Date Difference] = 50, "New",
        [Date Difference] = 152, "Old",
        "Other"
    )
    • UK_User123456's avatar
      UK_User123456
      Resolver I

      jdbuchanan71  Thanks for this, but it then throws out the error of MdxScript(Model) (140,98), 'SWITCH' does not support comparing values of type True/False with values of type text. I dont have any columns or values that are of Ture/False types, so not sure why it wont accept the measure?

       

      TIA

  • Hi UK_User123456 

     

    create a column:

     

    date diference = DATEDIFF(date1;date2;DAY)  (use semicolon or comma)
     
    create another column:
    text result = If (date diference <= 50;"New";date diference <= 150;"Existing";"Old")
     
    best regards.
    • UK_User123456's avatar
      UK_User123456
      Resolver I

      evandrocunico many thanks, will try this out. I have created a new column already for date diff and this throws out some random numbers, but I think I know where the issue lies.

       

      I will respond once I have had the chance to try it out.