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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.