help required with complex (well, i think so) statement in power query

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,053
Office Version
  1. 365
Platform
  1. Windows
Can anyone help with this formula. in excel i can manage it, but in M.... that's a different matter entirely. i am setting traffic lights to indicate progress on a report.



Col ACol BCol CCol DCol ECol FCol GCol HToday
ContractStart Date for Next ActivityEnd Date for Next Activity% CompleteDurationCalculated DaysProgress DateIndicator26/04/2024
BRD-STP-U-000418/12/20207/07/202360931558.629/06/2022RED
UW0013543/04/202331/07/20236511977.3519/06/2023RED
UW0010909/04/202430/04/202420214.213/04/2024AMBER
UW0004573/11/20231/03/202411903/11/2023RED
UW0004593/11/20231/03/20247511989.2531/01/2024RED
UW0007233/11/20231/03/20247511989.2531/01/2024RED
BRD-STP-R-00487/07/202322/03/202470259181.34/01/2024RED
UW0014578/03/202429/03/2024100212129/03/2024GREEN




the formula in excel for the Indicator colour is:

Code:
=IF(D2=100,"GREEN",IF(AND(OR(D2=0,D2=""),TODAY()>B2),"RED",IF((TODAY()-(B2+((D2/100)*E2)))>14,"RED",IF(AND((TODAY()-(B2+((D2/100)*E2)))<=14,(TODAY()-(B2+((D2/100)*E2)))>=0),"AMBER","GREEN"))))

Col D contains the % Completion of each project. So, if its 100%, excellent. GREEN. if its 0 or Null, AND we are past the start date, Bad RED.


 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The rest of the formula compares the progress date (start date plus (% completion x duration of project)) to today's date and if its inside 14 days over or under, Amber, greater than 14 days, RED, everything else Green.
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table4"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"Start Date for Next Activity", type date}, {"End Date for Next Activity", type date}}),
    today = Date.From(DateTime.LocalNow()),
    Result = Table.AddColumn(ChangeType, "Indicator color (as of " & Text.From(today) & ")", each let 
                startdate = [Start Date for Next Activity],
                enddate = [End Date for Next Activity],
                progress = if [#"% Complete"] = null then 0 else [#"% Complete"]/100,
                plannedduration = enddate - startdate,
                targetdate = Date.AddDays(startdate, Number.Round(Duration.Days(plannedduration)*progress)),
                daysfromtarget = Duration.Days(targetdate - today)
            in 
                if progress = 1 then "GREEN" else 
                if today > enddate then "RED" else 
                if Number.Abs(daysfromtarget) <= 14 then "AMBER" else 
                if daysfromtarget > 14 then "GREEN" else "RED") 
in
    Result

Book1
ABCDEF
1Table4
2ContractStart Date for Next ActivityEnd Date for Next Activity% Complete
3BRD-STP-U-000412/18/20207/7/202360
4UW0013544/3/20237/31/202365
5UW0010904/9/20244/30/202420
6UW00045711/3/20233/1/20240
7UW00045911/3/20233/1/202475
8UW00072311/3/20233/1/202475
9BRD-STP-R-00487/7/20233/22/202470
10UW0014573/8/20243/29/2024100
11
12
13Query Output
14ContractStart Date for Next ActivityEnd Date for Next Activity% CompleteIndicator color (as of 4/26/2024)
15BRD-STP-U-000412/18/20207/7/202360RED
16UW0013544/3/20237/31/202365RED
17UW0010904/9/20244/30/202420AMBER
18UW00045711/3/20233/1/20240RED
19UW00045911/3/20233/1/202475RED
20UW00072311/3/20233/1/202475RED
21BRD-STP-R-00487/7/20233/22/202470RED
22UW0014573/8/20243/29/2024100GREEN
23
Sheet4
 
Upvote 1
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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