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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
mariomyhanh
Helper I
Helper I

Dax if/then divide statement

Please help, i'm fairly new to DAX and I am trying create a measure to look at a column ([Level 2]) in a table ('COA Structure') that contains "Total Operating Expense" then apply this division formula to it  = DIVIDE([Variance],[Budgets]*-1,-1).  but if column has "Total Operating Revenue" then apply this division formula to it= DIVIDE([Variance],[Budgets]*1,1). i hope this makes sense. 

 

Thank you,

1 ACCEPTED SOLUTION

@mariomyhanh 
Please try

=
VAR Result =
    DIVIDE ( [Variance], [Budgets] )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'COA Structure'[Level 2] ),
        "Total Operating Expense", IFERROR ( - Result, -1 ),
        "Total Operating Revenue", IFERROR ( Result, 1 ),
        Result
    )

View solution in original post

8 REPLIES 8
tamerj1
Super User
Super User

Hi @mariomyhanh 

Please try

=
SUMX (
    VALUES ( 'COA Structure'[Level 2] ),
    SWITCH (
        'COA Structure'[Level 2],
        "Total Operating Expense", DIVIDE ( [Variance], [Budgets] * -1, -1 ),
        "Total Operating Revenue", DIVIDE ( [Variance], [Budgets] * 1, 1 )
    )
)

Thank you so much for the formula!!  It works.  Is there a way to customize the total . Currently, if revenue is -3.19 and expenses is 2.51. Total is -0.68. is there a way to customize the formula for row subtotal to calculate variance/budget ?

Thank you again so much.

@mariomyhanh 

Using the very same example, what should be the vslue of the total?

HI Tamerj1 total should be 2.5%.  but currently it's sum it to -0.68%

 BudgetVariance%Variance
revnue3,600,000(116,000)-3.2%
expense147,000,0003,700,0002.5%
total(143,400,000)3,584,000-2.5%

@mariomyhanh 
Please try

=
VAR Result =
    DIVIDE ( [Variance], [Budgets] )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'COA Structure'[Level 2] ),
        "Total Operating Expense", IFERROR ( - Result, -1 ),
        "Total Operating Revenue", IFERROR ( Result, 1 ),
        Result
    )

Thank you so much for all your help. Happy holidays. 

FreemanZ
Super User
Super User

Are Variance and Budgets columns or measures?

Hello FreemanZ, Variance and Budgets are measures.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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