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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
msoriano07
Frequent Visitor

How to correct my Multiple IF Statements with AND

Hello Everyone,

 

I am creating a report in power BI and trying to create mutiple IF Statements with AND in a column, just not sure how to correct this and now I am lost. As per screenshot below, it is saying the Function SUM is not allowed in Direct Query.

Please help!

 

Status = IF([ACCOUNT_NAME]="","",
IF(AND([ACCOUNT_TYPE]="IC Account",[CLOSING_BALANCE_AMOUNT]>0),"Receivable",
IF(AND([ACCOUNT_TYPE]="IC Account",[CLOSING_BALANCE_AMOUNT]<0),"Payable",
IF(AND([ACCOUNT_TYPE]="IC Account",[CLOSING_BALANCE_AMOUNT]=0),"-",
IF(AND([ACCOUNT_TYPE]="Bank Accountl",[Excess Cash / Funding Needed]>0),"Excess",
IF(AND([ACCOUNT_TYPE]="Bank Account",[Excess Cash / Funding Needed]<0),"Funding needed",
IF(AND([ACCOUNT_TYPE]="Bank Account",[Excess Cash / Funding Needed]=0),"-","")))))))

 

Screenshot 2025-08-07 212424.jpg

Thanks.

9 REPLIES 9
v-ssriganesh
Community Support
Community Support

Hi @msoriano07,
Thank you for posting your query in the Microsoft Fabric Community Forum, could you please provide sample data that clearly illustrates the issue you're experiencing?

  • Include a small dataset that fully captures the issue (preferably in table format or as a downloadable file, not just a screenshot).
  • Avoid including any sensitive or unrelated information.
  • Also share the expected outcome based on the sample data you provide.

Need help preparing or uploading sample data? You can refer to this helpful guide:
How to provide sample data in the Power BI Forum - Microsoft Fabric Community

This will help us reproduce your scenario accurately and provide a precise solution.

Best regards,
Ganesh Singamshetty.

Hello @msoriano07,

I am following up to see if you had a chance to review my previous response and provide the requested information. This will enable us to assist you further.

Thank you.

 

Hello @msoriano07,
Just checking in to see if you had a chance to review my earlier message and share the requested details. Once we have that, we’ll be better equipped to help you further. Thanks.

 

DataNinja777
Super User
Super User

Hi @msoriano07 ,

 

The error "Function SUM is not allowed in Direct Query" is happening because your formula for the Status calculated column refers to [Excess Cash / Funding Needed], which is likely a measure that uses an aggregation like SUM. In DirectQuery mode, you simply can't use measures or aggregation functions inside a calculated column. This is because a calculated column is computed one row at a time during data refresh and doesn't have the overall "context" needed to perform an aggregation for each individual row.

 

The correct solution is to move your logic out of a calculated column and into a measure. Measures are designed for this exact scenario; they are calculated on the fly when you use them in a visual and can easily reference other measures. It's also a great opportunity to simplify your formula by using the SWITCH function instead of many nested IFs. It's much cleaner and more efficient. In Power BI, click on New Measure and paste the following DAX code.

Status Measure =
-- The SWITCH(TRUE(), ...) pattern allows checking multiple logical conditions in order.
SWITCH(
    TRUE(),
    -- First, check if the account name is blank.
    SELECTEDVALUE('YourTable'[ACCOUNT_NAME]) = "", BLANK(),

    -- Condition for "Receivable"
    SELECTEDVALUE('YourTable'[ACCOUNT_TYPE]) = "IC Account" && [CLOSING_BALANCE_AMOUNT] > 0, "Receivable",

    -- Condition for "Payable"
    SELECTEDVALUE('YourTable'[ACCOUNT_TYPE]) = "IC Account" && [CLOSING_BALANCE_AMOUNT] < 0, "Payable",

    -- Condition for "Excess"
    -- This now works because [Excess Cash / Funding Needed] is evaluated within a measure.
    SELECTEDVALUE('YourTable'[ACCOUNT_TYPE]) = "Bank Account" && [Excess Cash / Funding Needed] > 0, "Excess",

    -- Condition for "Funding needed"
    SELECTEDVALUE('YourTable'[ACCOUNT_TYPE]) = "Bank Account" && [Excess Cash / Funding Needed] < 0, "Funding needed",

    -- Default condition for all zero balances or other cases
    "-"
)

Remember to replace 'YourTable' with the actual name of your table. I used SELECTEDVALUE because measures operate on the aggregated context of your visual. When you use this new [Status Measure] in a table or chart, it will correctly evaluate the conditions, including your other measure, and display the right status without the DirectQuery error. The SWITCH function makes the logic much easier to read by listing each condition and its result in a clear sequence, avoiding the confusing mess of nested parentheses.

 

Best regards,

Hello Thank you so much for answering.

So far, your answer is the closest with less error. I just can't understand why the closing balancecannot be determined. 

2025-08-08 00_21_23-Cash Balance Monitoring_v2.png 

wardy912
Impactful Individual
Impactful Individual

Hi @msoriano07 

 

 In direct query, functions like SUM, AVERAGE etc. are restricted to measures.

 

Your corrected calculated column is as follows:

 

Status = 
IF(
    [ACCOUNT_NAME] = "", 
    "", 
    SWITCH(
        TRUE(),
        [ACCOUNT_TYPE] = "IC Account" && [CLOSING_BALANCE_AMOUNT] > 0, "Receivable",
        [ACCOUNT_TYPE] = "IC Account" && [CLOSING_BALANCE_AMOUNT] < 0, "Payable",
        [ACCOUNT_TYPE] = "IC Account" && [CLOSING_BALANCE_AMOUNT] = 0, "-",
        [ACCOUNT_TYPE] = "Bank Account" && [Excess Cash / Funding Needed] > 0, "Excess",
        [ACCOUNT_TYPE] = "Bank Account" && [Excess Cash / Funding Needed] < 0, "Funding needed",
        [ACCOUNT_TYPE] = "Bank Account" && [Excess Cash / Funding Needed] = 0, "-",
        ""
    )
)

 

I hope this helps, please give a thumbs up and mark as solved if it does, thanks!

MohamedFowzan1
Responsive Resident
Responsive Resident

Hi @msoriano07 

 

Yes Direct query has some limitations

 

You could create this as a measure if you would like to use sums:

Status =
IF(
    SELECTEDVALUE([ACCOUNT_NAME]) = "", BLANK(),
    IF(
        AND([ACCOUNT_TYPE] = "IC Account", [CLOSING_BALANCE_AMOUNT] > 0), "Receivable",
        IF(
            AND([ACCOUNT_TYPE] = "IC Account", [CLOSING_BALANCE_AMOUNT] < 0), "Payable",
            IF(
                AND([ACCOUNT_TYPE] = "IC Account", [CLOSING_BALANCE_AMOUNT] = 0), "-",
                IF(
                    AND([ACCOUNT_TYPE] = "Bank Account", [Excess Cash / Funding Needed] > 0), "Excess",
                    IF(
                        AND([ACCOUNT_TYPE] = "Bank Account", [Excess Cash / Funding Needed] < 0), "Funding needed",
                        IF(
                            AND([ACCOUNT_TYPE] = "Bank Account", [Excess Cash / Funding Needed] = 0), "-",
                            BLANK()
                        )
                    )
                )
            )
        )
    )
)

  

else you would have to Use Only Columns (Not Measures) within in the Calculated Columns e.g [Excess Cash / Funding Needed] would have to also be a column instead of measure

Greg_Deckler
Community Champion
Community Champion

@msoriano07 Try this:

Status = 
  SWITCH( TRUE(),
    [ACCOUNT_NAME]="","",
    [ACCOUNT_TYPE]="IC Account" && [CLOSING_BALANCE_AMOUNT]>0,"Receivable",
    [ACCOUNT_TYPE]="IC Account" && [CLOSING_BALANCE_AMOUNT]<0,"Payable",
    [ACCOUNT_TYPE]="IC Account" && [CLOSING_BALANCE_AMOUNT]=0,"-",
    [ACCOUNT_TYPE]="Bank Accountl" && [Excess Cash / Funding Needed]>0,"Excess",
    [ACCOUNT_TYPE]="Bank Account" && [Excess Cash / Funding Needed]<0),"Funding needed",
    [ACCOUNT_TYPE]="Bank Account" && [Excess Cash / Funding Needed]=0),"-",
    ""
  )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks a lot for answering but I am still having issue ☹️

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors