Solution based on python:
let
BufferedTAB1 = Table.Buffer(TAB1),
BufferedTAB2 = Table.Buffer(TAB2),
PythonStep = Python.Execute(
"
import pandas as pd
import re
# Import data from Power Query
tab1 = dataset1.copy()
tab2 = dataset2.copy()
results = pd.DataFrame()
# Cross join
tab1['key'] = 1
tab2['key'] = 1
for _, row1 in tab1.iterrows():
row1_df = pd.DataFrame([row1])
merged = pd.merge(row1_df, tab2, on='key').drop('key', axis=1)
mask = merged.apply(lambda row: bool(re.match(str(row['MASK']), str(row['ACCOUNT']))), axis=1)
filtered = merged[mask]
results = pd.concat([results, filtered], ignore_index=True)
",
[
dataset1 = BufferedTAB1,
dataset2 = BufferedTAB2
]
),
TAB3 = PythonStep{[Name="results"]}[Value],
Result = Table.SelectColumns(TAB3, {"GR", "PRODUCT", "ACCOUNT"})
in
Result