(disclaimer: I am not familiar with Power Bi, so I am answering this based on the remainder of your question).
Let's say the data is
import polars as pl
df = pl.DataFrame({"Country": ["USA", "USA", "Japan"],
"amount": [100, 200, 400]})
shape: (3, 2)
┌─────────┬────────┐
│ Country ┆ amount │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════════╪════════╡
│ USA ┆ 100 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ USA ┆ 200 │
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
│ Japan ┆ 400 │
└─────────┴────────┘
You could define your expression in the configuration file as follows:
expr = pl.col('amount').filter(pl.col('Country')=='USA').sum()
and in your code base you could do
from <expression file above> import expr
df.select(expr)
shape: (1, 1)
┌────────┐
│ amount │
│ --- │
│ i64 │
╞════════╡
│ 300 │
└────────┘
If the configuration file should be plain text (would strongly advise against this, because unsafe, not testable, no tooling support, etc), you could store in the config file
pl.col('amount').filter(pl.col('Country')=='USA').sum()
and read this as expr
in your Python code, and use eval
:
expr = <read config file as string>
df.select(eval(expr))