converting a excel formula to work in PowerQuery

Lyndonu

New Member
Joined
Jun 22, 2018
Messages
5
I'm new to PowerQuery, so what I'm attempting is way over my head.

In the following table, I've identified the earliest duplicate JobID value (by sorting the timestamp row earliest to latest), and then have populated the identified earliest Estimate Values into column E. (Ultimately I need to know the value of the first estimate uploaded for each JobID so I can track the changes made later.)

1633545434396.png


formulas for D2 is =(COUNTIF($C$2:C2,C2)>=2)+0
for E2 is =IF(D2=0,B2,"")

How could I accomplish creating the Initial Estimate Value column with powerquery? or is it even possible?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Cannot manipulate data in a picture. Please reload the data to this site using XL2BB so we don't have to recreate the data you already have.

I will attempt to walk you through this without using the data, however.

With your data in the PQ editor. Highlight the Job ID and select Group By. New column Name is Earliest, and you are selecting the Time Stamp Column and selecting Min.
This will give you the earliest estimate for each Job ID.
 
Upvote 0
Book2
ABCDE
1TimeStampEstimate ValueJobIDEstimate OrderInitial Estimate Value
217/10/2018 12:41$9,000.00RB11110$9,000.00
327/11/2018 12:07$13,500.00FL421240$13,500.00
403/12/2018 13:34$12,000.00RB13470$12,000.00
503/12/2018 17:46$3,000.00FL115980$3,000.00
606/12/2018 12:28$6,350.00RB13130$6,350.00
712/12/2018 13:38$5,137.76RB13131 
812/12/2018 13:38$2,897.91RB21000$2,897.91
921/12/2018 12:27$3,701.80FL115981 
1031/12/2018 17:08$15,747.94RB1110$15,747.94
1102/01/2019 9:58$20,587.02FL421241 
1202/01/2019 11:57$39,580.35FL114000$39,580.35
1302/01/2019 13:52$5,591.57SC1010$5,591.57
1402/01/2019 14:07$8,415.25SC1011 
Sheet1
Cell Formulas
RangeFormula
D2:D14D2=(COUNTIFS($C$2:C2,C2)>=2)+0
E2:E14E2=IF(D2=0,B2,"")
 
Upvote 0
this isnt quite what I'm looking for.

I'd like to add a new column that shows the Initial Estimate Value column in line with the rest of the data as listed above in the table. The grouping feature removes columns, however I need to reference them for other calculations.

Columns A to C are provided to me. I need to add calculated column E to assist with other calculated columns not showing here (F to L). Column D is unnecessary as it was a helper column in Excel only. I'm really trying to automate this worksheet build so it doesnt need my ongoing input.
 
Upvote 0
Must be better ways than this, but try:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"TimeStamp", type datetime}, {"Estimate Value", type number}, {"JobID", type text}}),
    lst1 = Table.AddColumn(ChangeType, "OriginalEstimate", (x)=> 
        Table.Sort(Table.SelectRows(ChangeType, each (x[JobID] = _[JobID])),{{"TimeStamp", Order.Ascending}}))[OriginalEstimate],
    lst2 = List.Transform(lst1, each _[Estimate Value]{0}),
    Result = Table.FromColumns(Table.ToColumns(ChangeType) & {lst2}, Table.ColumnNames(ChangeType) & {"Original Estimate"})
in
    Result

delme1R1.xlsm
ABCDEFGHI
1TimeStampEstimate ValueJobIDTimeStampEstimate ValueJobIDOriginal Estimate
210/17/18 12:419000RB111110/17/2018 12:419000RB11119000
311/27/18 12:0713500FL4212411/27/2018 12:0713500FL4212413500
412/3/18 13:3412000RB134712/3/2018 13:3412000RB134712000
512/3/18 17:463000FL1159812/3/2018 17:463000FL115983000
612/6/18 12:286350RB131312/6/2018 12:286350RB13136350
712/12/18 13:385137.76RB131312/12/2018 13:385137.76RB13136350
812/12/18 13:382897.91RB210012/12/2018 13:382897.91RB21002897.91
912/21/18 12:273701.8FL1159812/21/2018 12:273701.8FL115983000
1012/31/18 17:0815747.94RB11112/31/2018 17:0815747.94RB11115747.94
111/2/19 9:5820587.02FL421241/2/2019 9:5820587.02FL4212413500
121/2/19 11:5739580.35FL114001/2/2019 11:5739580.35FL1140039580.35
131/2/19 13:525591.57SC1011/2/2019 13:525591.57SC1015591.57
141/2/19 14:078415.25SC1011/2/2019 14:078415.25SC1015591.57
15
Sheet7
 
Upvote 0

Forum statistics

Threads
1,223,697
Messages
6,173,896
Members
452,536
Latest member
Chiz511

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