Excel Power Query Max number

kaz123

New Member
Joined
Oct 8, 2017
Messages
31
Hi

I have the below Power Query that helps me group absences for each employee. I wanted to find out how to limit the Total Days value (highlighted below) to 262.

= Table.Group(Source, {"Absence Type", "Employee name", "Employee Type", "Employee ID", "Department"}, {{"Total Days", each List.Sum([Total Days]), type number}, {"Excluding Days", each List.Sum([Excluding Days]), type number}})


Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Replace List.Sum([Total Days]) with List.Min({List.Sum([Total Days]),262})
 
Upvote 0
Replace List.Sum([Total Days]) with List.Min({List.Sum([Total Days]),262})
Thanks, this limits that field to 262 when it exceeds that number. The only other question I had was if its possible to reference a lookup table within the power query? This is because the next field 'Excluding Days' should be "Total Days" value minus the allowance value based on the "Absence Type" which is held on the same workbook as a named range.

Absence TypeAllowance
Sick20
Medical10
Study Leave15



So if the "Total Days" value is limited to 262, the "Excluding Days" should be 242
 
Upvote 0
Yes - bring the lookup table (change the name in quotes to your table name) into your query with a step like like:

tblLU = Excel.CurrentWorkbook(){[Name="Lookup Table Name"]}[Content]

then to get the allowance you would use something like:

= Table.Group(Source, {"Absence Type", "Employee name", "Employee Type", "Employee ID", "Department"}, let LS = List.Min({List.Sum([Total Days]),262}) in {{"Total Days", each LS, type number}, {"Excluding Days", each LS - tblLU{[Absence Type = _[Absence Type]]}[Allowance], type number}})

might work, I didn't test it.
 
Upvote 0
Yes - bring the lookup table (change the name in quotes to your table name) into your query with a step like like:

tblLU = Excel.CurrentWorkbook(){[Name="Lookup Table Name"]}[Content]

then to get the allowance you would use something like:

= Table.Group(Source, {"Absence Type", "Employee name", "Employee Type", "Employee ID", "Department"}, let LS = List.Min({List.Sum([Total Days]),262}) in {{"Total Days", each LS, type number}, {"Excluding Days", each LS - tblLU{[Absence Type = _[Absence Type]]}[Allowance], type number}})

might work, I didn't test it.
Thanks for the above, I am getting the error message below:

An error occurred in the ‘’ query. Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?

My full query is as below:

= let

tblLU = Excel.CurrentWorkbook(){[Name=“absence_table”]}[Content],

Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

Group = Table.Group(Source, {"Absence Type", “Employee name", “Employee Type", “Employee ID", “Department”}, let LS = List.Min({List.Sum([Total Days]),262}) in {{"Total Days", each LS, type number}, {"Excluding Days", each LS - tblLU{[Absence Type = _[Absence Type]]}[Allowance], type number}})

in
Group
 
Upvote 0
What happens if you use this instead:

Group = Table.Group(Source, {"Absence Type", “Employee name", “Employee Type", “Employee ID", “Department”}, let LS = List.Min({List.Sum([Total Days]),262}) in {{"Total Days", each LS, type number}, {"Excluding Days", each LS - tblLU{tblLU[Absence Type = _[Absence Type]]}[Allowance], type number}})

if it still errors out then if you can include representative sample of your Source table I may be able to debug it
 
Upvote 0
What happens if you use this instead:

Group = Table.Group(Source, {"Absence Type", “Employee name", “Employee Type", “Employee ID", “Department”}, let LS = List.Min({List.Sum([Total Days]),262}) in {{"Total Days", each LS, type number}, {"Excluding Days", each LS - tblLU{tblLU[Absence Type = _[Absence Type]]}[Allowance], type number}})

if it still errors out then if you can include representative sample of your Source table I may be able to debug it
Sorry for the late reply, I have attached an image showing the source data and what the final data should look like after running the power query. The only issue I have is the "Excluding Days" field should be "Total Days" minus the allowance for the absence type on the lookup table
 

Attachments

  • Screenshot 2021-12-08 at 16.26.17.png
    Screenshot 2021-12-08 at 16.26.17.png
    175.7 KB · Views: 4
Upvote 0
try

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="SourceData"]}[Content],
    tblLU = Excel.CurrentWorkbook(){[Name="LookupTable"]}[Content],
    Group = Table.Group(Source, {"Absence Type", "Employee Name", "Employee Type", "Employee ID", "Department"}, 
         {{"Total Days", each let LS = List.Min({List.Sum([Total Days]),262}) in LS, type number}}),
    Result = Table.AddColumn(Group,"Excluding Days", each [Total Days] - tblLU{[Absence Type = _[Absence Type]]}[Allowance])

in
    Result
 
Upvote 0
Solution
try

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="SourceData"]}[Content],
    tblLU = Excel.CurrentWorkbook(){[Name="LookupTable"]}[Content],
    Group = Table.Group(Source, {"Absence Type", "Employee Name", "Employee Type", "Employee ID", "Department"},
         {{"Total Days", each let LS = List.Min({List.Sum([Total Days]),262}) in LS, type number}}),
    Result = Table.AddColumn(Group,"Excluding Days", each [Total Days] - tblLU{[Absence Type = _[Absence Type]]}[Allowance])

in
    Result
Thank you , this works
 
Upvote 0

Forum statistics

Threads
1,215,056
Messages
6,122,907
Members
449,096
Latest member
dbomb1414

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