r/ExcelPowerQuery • u/Retro_infusion • Feb 06 '25
Create table variables from excel to update query
I have this table in excel which has been loaded into PQ
min-- max -- diff range
0----- 20 ----- 0
20----- 40 ----- 1
40----- 60 ----- 2
60----- 80----- 3
80---- 100 ----- 4
I have a column in a query called Probability that has decimals from 0 to 100.
I would like to create a new column to assign the values in Probability with the diff range values when they fall between the min and max from the table above. I would end up with the Probability column with the original values and a new column with diff range values. for example a value of 43.2 would get a diff range value of 2.
It is important that I can change these values in the table above when needed from the excel sheet and refresh the query to show the updated values.
1
u/tj15241 Feb 07 '25
You can use the values in your example table as an input. If you google dynamic input power query you should get a bunch of different solutions
1
u/johndering Feb 07 '25
Here’s a good reference for the lookup or merge way of joining the columns of your two tables:
https://community.fabric.microsoft.com/t5/Desktop/Power-Query-LookUp-in-another-table/td-p/2591843
1
u/johndering Feb 07 '25
Using list lookup to extract Diff_Range[Diff Range] value for each value of Main_Table[Probability], as a new column, using the following PQ script:
= Table.AddColumn(#"Changed Type", "Diff_Range", each let x = [Probability] in Diff_Range[Diff Range]{List.Count(List.Select(Diff_Range[Min], each _ <= x))-1}, Int64.Type)HTH.