Forum Discussion

Danielnir's avatar
Danielnir
Helper II
3 years ago
Solved

Simplifying Dax Formula To Make it Perform Faster

Hi Everyone!   Need help with tweaking the performance of DAX formula. I had to recreate the way Sage200c generates sales report. The code I ended up with looks like this:   Sales Value = var ...
  • ReneMoawad's avatar
    3 years ago

    Hi Daniel,

     

    First you need to create a New Column with the below formula:

     

    Total Value GBP =
    Var CreditType = RELATED('SOPInvoiceCreditType'[Name])
    Var ReturnTypeName = RELATED('SOPOrderReturnType'[SOPOrderReturnTypeName])
    RETURN
    SWITCH(TRUE()
        , CreditType = "Credit Note" && ReturnTypeName <> "Quotation", 'SOPInvoiceCreditLine'[LineTotalValueGBP] * -1
        , CreditType = "Invoice" && ReturnTypeName <> "Quotation", 'SOPInvoiceCreditLine'[LineTotalValueGBP]
        , BLANK()
    )


    And after that create the below measure:


    Sales Value =
    Var selectedCurrency = SELECTEDVALUE('DIM: Currency Exchange'[Currency])
    Var currencyExchange = SELECTEDVALUE('DIM: Live Currency Exchange'[USD per unit])
    RETURN
    IF(selectedCurrency = "GBP", [Total Value GBP], [Total Value GBP] * currencyExchange)