Custom Column based on Date in another column

karmaimages

Board Regular
Joined
Oct 1, 2009
Messages
112
Office Version
  1. 365
Platform
  1. Windows
Hi

I have a list of SLA due dates in a column called "SLA"

I need to create a new column based on those dates which will create a text value in the new column based on the following:

if SLA date = date in past and not equal to today then value = Over Due
If SLA date = due today or next 30 days then value = SLA Due within 30 days
if SLA date = >30 days then value = within SLA

Is this possible to do within PowerBi?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Yes. DateTime.LocalNow() returns the current date and time so: convert that to just a date, then it's a series of if statements. For example:

Power Query:
=let today = Date.From(DateTime.LocalNow()) in if [SLA Date] < today then "Over Due" else if [SLA Date] < Date.AddDays(today, 30) then "Due today or next 30 days" else "within SLA"
 
Upvote 0
Solution
Power Query:
=let today = Date.From(DateTime.LocalNow()) in if [SLA Date] < today then "Over Due" else if [SLA Date] < Date.AddDays(today, 30) then "Due today or next 30 days" else "within SLA"
That worked perfectly, thank you very much
 
Upvote 0
Yes. DateTime.LocalNow() returns the current date and time so: convert that to just a date, then it's a series of if statements. For example:

Power Query:
=let today = Date.From(DateTime.LocalNow()) in if [SLA Date] < today then "Over Due" else if [SLA Date] < Date.AddDays(today, 30) then "Due today or next 30 days" else "within SLA"

One query on this, if I have a blank date within [SLA Date] can I get it to ignore this rather than create an error or enter something like "Data Missing"
 
Upvote 0
You'll need to handle that separately first with another if:
Power Query:
if [SLA Date] = null then "whatever" else ...
 
Upvote 0
You'll need to handle that separately first with another if:
Power Query:
if [SLA Date] = null then "whatever" else ...
I tried:

Power Query:
= Table.AddColumn(#"Changed Type3", "In/Out of SLA", each let today = Date.From(DateTime.LocalNow()) in if [SLA] < today then "Over Due" else if [SLA] < Date.AddDays(today, 30) then "Due today/Next 30 days" else if [SLA] = null then "Information Missing" else "Within SLA")

But this is still throwing an error:

Expression.Error: We cannot convert the value null to type Logical.
Details:
Value=
Type=[Type]
 
Upvote 0
You need the null test to be the first one.
 
Upvote 0

Forum statistics

Threads
1,223,941
Messages
6,175,537
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top