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
CiaraCaryl
Frequent Visitor

Help Converting Excel Formula to DAX

Could someone please help me convert this excel formula to DAX? I was thinking I could use the Switch function but I am having trouble formatting it correctly.

IF([@InvoiceDate]>DATE(2020,12,31),
(IF([@[ProductType_Sub3]]="monthly",([@ExtensionAmt]*72),
(IF([@[ProductType_Sub3]]="yearly",([@ExtensionAmt]*6),
(IF([@[ProductType_Sub3]]="5 Year",([@ExtensionAmt]/5)*6,
(IF([@[ProductType_Sub3]]="4 Year",([@ExtensionAmt]/4)*6,
(IF([@[ProductType_Sub3]]="3 Year",([@ExtensionAmt]/3)*6,
(IF([@[ProductType_Sub3]]="2 Year",([@ExtensionAmt]/2)*6,)))))))))))),
(IF([@[ProductType_Sub3]]="monthly",([@ExtensionAmt]*36),
(IF([@[ProductType_Sub3]]="yearly",([@ExtensionAmt]*3),"")))))

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @CiaraCaryl , hello, Brightsider & Greg_Deckler , thank you for your promot reply!

We could also use the following measure to meet your requirement:

 

Result = 
SWITCH(
    TRUE(),
    SELECTEDVALUE('Table'[InvoiceDate])> DATE(2020, 12, 31),
        SWITCH(
            TRUE(),
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "monthly", SELECTEDVALUE('Table'[ExtensionAmt]) * 72,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "yearly", SELECTEDVALUE('Table'[ExtensionAmt]) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "5 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 5) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "4 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 4) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3])= "3 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 3) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "2 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 2) * 6,
            BLANK()
        ),
   SELECTEDVALUE('Table'[ProductType_Sub3]) = "monthly", SELECTEDVALUE('Table'[ExtensionAmt]) * 36,
    SELECTEDVALUE('Table'[ProductType_Sub3]) = "yearly", SELECTEDVALUE('Table'[ExtensionAmt]) * 3,
    BLANK()
)

 

Best regards,

Joyce

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @CiaraCaryl , hello, Brightsider & Greg_Deckler , thank you for your promot reply!

We could also use the following measure to meet your requirement:

 

Result = 
SWITCH(
    TRUE(),
    SELECTEDVALUE('Table'[InvoiceDate])> DATE(2020, 12, 31),
        SWITCH(
            TRUE(),
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "monthly", SELECTEDVALUE('Table'[ExtensionAmt]) * 72,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "yearly", SELECTEDVALUE('Table'[ExtensionAmt]) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "5 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 5) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "4 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 4) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3])= "3 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 3) * 6,
            SELECTEDVALUE('Table'[ProductType_Sub3]) = "2 Year", (SELECTEDVALUE('Table'[ExtensionAmt]) / 2) * 6,
            BLANK()
        ),
   SELECTEDVALUE('Table'[ProductType_Sub3]) = "monthly", SELECTEDVALUE('Table'[ExtensionAmt]) * 36,
    SELECTEDVALUE('Table'[ProductType_Sub3]) = "yearly", SELECTEDVALUE('Table'[ExtensionAmt]) * 3,
    BLANK()
)

 

Best regards,

Joyce

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

Brightsider
Resolver I
Resolver I

Try:

IF([InvoiceDate] > DATE(2020, 12, 31),
SWITCH( TRUE,
    [ProductType_Sub3] = "monthly", ([ExtensionAmt * 72),
    [ProductType_Sub3] = "yearly", ([ExtensionAmt * 6),
    [ProductType_Sub3] = "5 Year", (([ExtensionAmt / 5) * 6),
    [ProductType_Sub3] = "4 Year", (([ExtensionAmt / 4) * 6),
    [ProductType_Sub3] = "3 Year", (([ExtensionAmt / 3) * 6),
    [ProductType_Sub3] = "2 Year", (([ExtensionAmt / 2) * 6),
    FALSE),
SWITCH(TRUE,
    [ProductType_Sub3] = "monthly", ([ExtensionAmt * 36),
    [ProductType_Sub3] = "yearly", ([ExtensionAmt * 3),
    FALSE
))

 

think captured what the formula's trying to do. You might have to monkey with it to get it to fit. 🙂 

Greg_Deckler
Super User
Super User

@CiaraCaryl Technically the same IF syntax should technically work in DAX. That said, a SWITCH( TRUE(), ... ) statement would be preferred. That's a lot of nested IF statements though. It's hard to decipher with the poor formatting so I would start by properly formatting the IF statements and then it should be easier to figure out the logic.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.