Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
tomas12344
Helper III
Helper III

Conditionally invoke function or run statement

Hi All

Customer want to load some data from SAP query, but the problem is, that in this case I have to call several times this query with different filters (basic probelm is that the query in SAP has too many rows and the data cannot be loaded within the 5hours limit of Service, but this is not the question. So we decideded, that the query will be loaded by years).

The question is, if in power query it is posible to excecute  conditionaly some statements or invoke some function. somthing like in C++ (not define a conditional calculation of some column).

Some example:
- have a query A, which contain several columns to load,...

- than I need to invoke this query A and add some filter FA, and second invocation would need to have some filter FB.

- is it posible to define within the query A and condtion, base on some parameter like 

if Parm1=1 then do filter FA

else do filter FB

(FA, FB are some fitering statements written in Power query)

 

I found out, that I can store the query A as function, then invoke it and just add the filter FA or FB. But this would create lot of aditional queries/function, whic is not so optimal for maintanance, as this would need to have defined query A_FA and A_FB,... and call them as separete invocation.

 

1 ACCEPTED SOLUTION
ManuelBolz
Responsive Resident
Responsive Resident

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

View solution in original post

1 REPLY 1
ManuelBolz
Responsive Resident
Responsive Resident

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors