Forum Discussion
LOOP to Look up the value in M Query
- 6 years ago
Hi, qsong
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may go to 'Query Editor'=>'Add Column'=>'Custom Column', input the following codes.
let country=[Country],date=[Date], tab = Table.SelectRows( #"Changed Type", each [Country]=country and [Date]<date and [Value]<100 ) in if Table.RowCount(tab)>0 then if [Value]>100 then Table.Max(tab,"Date")[Value] else [Value] else if [Value]<100 then [Value] else 100Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, qsong
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may go to 'Query Editor'=>'Add Column'=>'Custom Column', input the following codes.
let
country=[Country],date=[Date],
tab = Table.SelectRows(
#"Changed Type",
each [Country]=country and [Date]<date and [Value]<100
)
in
if Table.RowCount(tab)>0
then
if [Value]>100
then Table.Max(tab,"Date")[Value]
else [Value]
else
if [Value]<100
then [Value]
else 100
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Fowmy6 years agoSuper User
Hi v-alq-msft
That is a neat solution!
I am very much interested in improving my M skills; can you direct me to some M language resources for deep learning of the language?
Thanks
Fowmy - qsong6 years agoHelper II