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
Anonymous
Not applicable

Set an IF for different dates

My table follows this structure:

datecolumn1column2
02/01/2020 111222
03/03/2020222777
07/10/2020333555
12/12/2020444999

 

I want to create a new column that, if the date is less than 05/05/2020, then the values will be taken from column1. If the date is greater than 05/05/2020, the value will be taken from column2.

 

The expected result would look like this:

datecolumn1column2new_column
02/01/2020 111222111
12/12/2020222777777
07/10/2020333555555
04/04/2020444999444

 

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

HI @Anonymous ,

 

NEW_COLUMN = IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2])


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
Anonymous
Not applicable

@camargos88 
@Pragati11 
@amitchandak 
Thanks to everyone for the quick responses! Worked perfectly!

Just a small question before closing the topic: is it possible to insert Hour in this DATE function too? In case I wanted to get values ​​from a specific day and time?

Hi @Anonymous ,

 

There is quite interesting article on how you can use date and time functions in Power BI:

https://medium.com/@kishoripatil1823/date-and-time-dax-functions-in-power-bi-fd9155416178

 

Try checking it out and see how you can implement it in your scenario.

 There is a TIME function in Power BI which you can use. There is an existing thread for this. Check it:

https://community.powerbi.com/t5/Desktop/DAX-IF-statement-based-on-TIME/td-p/889249

 

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

amitchandak
Super User
Super User

@Anonymous , Try like

 

new column = IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2])

new measure = IF(max('Table'[date]) < DATE(2020,5,5), max('Table'[column1]), max('Table'[column2]))

new measure = sumx('Table', IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2]))

Pragati11
Super User
Super User

HI @Anonymous ,

 

You can create a calculated column as follows:

 

NewValueCol = IF(Tablename[date] < DATE(2020, 05, 05), Tablename[Column 1], Tablename[Column 2])

 

Replace Tablename[date] in above DAX with your table and column.

 

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

camargos88
Community Champion
Community Champion

HI @Anonymous ,

 

NEW_COLUMN = IF('Table'[date] < DATE(2020,5,5), 'Table'[column1], 'Table'[column2])


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.