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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Edmundo
Regular Visitor

IF function that depends on month number

Hello everyone,

 

I need to calculate Return on assets ratio as annual but don't know how to write IF funcion that depends on month number in table below 

 

ROA = DIVIDE(CALCULATE(SUM(UK_DB[Sum, Eur]),UK_DB[Item]="Net profit"), CALCULATE(SUM(UK_DB[Sum, Eur]),UK_DB[Item]="Assets"))*IF([Date][month]=3;4;IF([Date][month]=6;2;IF([Date][month]=9;1.3333;1)

 

Could you please help me with the formula marked in red?

Edmundo_0-1634886385961.png

 

1 ACCEPTED SOLUTION
ibarrau
Super User
Super User

Hi. I'll help you with the IF statement taking actual/current date regarding the row context of a visualization. I have added comments to help you. It would be a good idea to use variables. You can find your IF with variables and the __better_if that is kind of a better solution for that in case you want to replace it.

 

ROA = 
VAR __current_date = SELECTEDVALUE( Table[Data] ) //Your table example specifies column data as date. This gets the current date in row context
VAR __month = MONTH (__current_date) //if your column is type date you can do this to get the month
VAR __if_condition = 
    IF(__month = 3, 4 
        , IF(__month = 6, 2
            , IF(__month = 9, 1.3333, 1
            )
        )
    )
VAR __better_if = // this would be a better way to handle the if
SWITCH (__month
    , 3, 4
    , 6, 2
    , 9, 1.333
    ,1
)
RETURN
DIVIDE(
    CALCULATE( SUM( UK_DB[Sum, Eur] ), UK_DB[Item] = "Net profit" )
    , CALCULATE( SUM(UK_DB[Sum, Eur]), UK_DB[Item] = "Assets" )
) * __if_condition

 

 I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

View solution in original post

1 REPLY 1
ibarrau
Super User
Super User

Hi. I'll help you with the IF statement taking actual/current date regarding the row context of a visualization. I have added comments to help you. It would be a good idea to use variables. You can find your IF with variables and the __better_if that is kind of a better solution for that in case you want to replace it.

 

ROA = 
VAR __current_date = SELECTEDVALUE( Table[Data] ) //Your table example specifies column data as date. This gets the current date in row context
VAR __month = MONTH (__current_date) //if your column is type date you can do this to get the month
VAR __if_condition = 
    IF(__month = 3, 4 
        , IF(__month = 6, 2
            , IF(__month = 9, 1.3333, 1
            )
        )
    )
VAR __better_if = // this would be a better way to handle the if
SWITCH (__month
    , 3, 4
    , 6, 2
    , 9, 1.333
    ,1
)
RETURN
DIVIDE(
    CALCULATE( SUM( UK_DB[Sum, Eur] ), UK_DB[Item] = "Net profit" )
    , CALCULATE( SUM(UK_DB[Sum, Eur]), UK_DB[Item] = "Assets" )
) * __if_condition

 

 I hope that helps,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.