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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
viveksasi94
Helper I
Helper I

How to substitute a Date with a String without changing the data type to string

Greetings Datanuts, I have a date column whose data type is Date. I need to replace a specific date in the date column with a String. If I change the data type of the column to Text it is not sorting properly(i.e earliest date should come first). Note - MY_MODEL[Snapshot Date] data type is Date/time TEST = IF(MY_MODEL[Snapshot Date]=31/12/9999,"Live",MY_MODEL[Snapshot Date]) Error - Expressions that yield variant data-type cannot be used to define calculated columns. Any help is appreciated 🙂
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@viveksasi94

 

I am not sure if I understand your question clearly. I think if you want to return the value as text and date type, you need to unify the type.

 

In my example, the type of data column is date and the type of date2 type is TEXT.

 

Hope this is helpful. Thanks

 

checkdate = if('Table1'[date]=DATE(2018,01,01),"Live",FORMAT('Table1'[date],""))
checktext = if(Table1[date2]="1/1/2018","Live",Table1[date2])

 

c1.JPG





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
v-cherch-msft
Employee
Employee

Hi @viveksasi94

 

Could you tell me if your problem has been solved? If it is,kindly mark the helpful answer as a solution and welcome to share your own solution. More people will benefit from here. If not, please share more details for us so that we could help further on it.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-cherch-msft
Employee
Employee

Hi @viveksasi94

 

You need to unify the type to "Text" for the column as ryan_mayu said. If you need to sort the column, you may try to add an index column in query editor and use 'Sort by column' by index column.Below are some posts about this feature for your reference.

https://community.powerbi.com/t5/Desktop/Creative-x-axel-in-power-bi-graph/m-p/590607#M280203

https://community.powerbi.com/t5/Desktop/Two-level-sorting-Matrix/m-p/507745#M237204

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ryan_mayu
Super User
Super User

@viveksasi94

 

I am not sure if I understand your question clearly. I think if you want to return the value as text and date type, you need to unify the type.

 

In my example, the type of data column is date and the type of date2 type is TEXT.

 

Hope this is helpful. Thanks

 

checkdate = if('Table1'[date]=DATE(2018,01,01),"Live",FORMAT('Table1'[date],""))
checktext = if(Table1[date2]="1/1/2018","Live",Table1[date2])

 

c1.JPG





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

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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