Forum Discussion
Conditionally invoke function or run statement
- 2 years ago
Hello tomas12344,
I'm not sure if I understood you correctly. But maybe the following code will help you.let LoadSAPData = (FilterParameter as text) as table => let Source = ... , // YOUR SAP QUERY FilteredData = if FilterParameter = "FA" then Table.SelectRows(Source, each [YearColumn] = 2020) else if FilterParameter = "FB" then Table.SelectRows(Source, each [YearColumn] = 2021) else Source in FilteredData in LoadSAPData
Best regards from Germany
Manuel Bolz
If this post helped you, please consider Accept as Solution so other members can find it faster.
🤝Follow me on LinkedIn
Hi tomas12344,
Using an if ... then ... else function is valid. The key is whether the year filter is pushed to SAP. If query folding works, SAP returns only the selected year. Otherwise, Power BI may retrieve a much larger dataset first.
For SAP BW, query variables or parameters are usually preferable.
If the same data is available through SAP OData, Power BI Connector for SAP can provide an alternative extraction path: https://www.sap.com/products/data-cloud/partners/metrica-software-inc-power-bi-connector-for-sap.html
It supports selecting the required entities and fields and applying SAP-side filters. It will not optimize the existing BW query, but it may reduce the transferred data. A 30-day free trial is available.
Documentation:
https://metricasoftware.com/docs/sap/
Cheers,
Metrica Team