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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Danielnir
Helper II
Helper II

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 Invoices = calculate(
                            sum('SOPInvoiceCreditLine'[LineTotalValueGBP]),
                            'SOPInvoiceCreditType'[Name]="Invoice",
                            'SOPOrderReturnType'[SOPOrderReturnTypeName]<>"Quotation")
var CreditNote = calculate(
                            sum('SOPInvoiceCreditLine'[LineTotalValueGBP]),
                            'SOPInvoiceCreditType'[Name]="Credit Note",
                            'SOPOrderReturnType'[SOPOrderReturnTypeName]<>"Quotation")*-1
Var SalesValue = calculate(
                            invoices+CreditNote,
                            filter(
                                SOPOrderReturnType,
                                SOPOrderReturnType[SOPOrderReturnTypeName]<>"Quotation"))

Return

IF(SELECTEDVALUE('DIM: Currency Exchange'[Currency])="GBP",SalesValue,SalesValue*SELECTEDVALUE('DIM: Live Currency Exchange'[USD per unit]))

 

 

When I run a performance analyzer, this formula and a corresponding one with the volumes (same code, different column in sum) takes the longest time to calculate. Is there any way to simplify them?

 

Thanks in advance!

 

1 ACCEPTED SOLUTION
ReneMoawad
Resolver III
Resolver III

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)

View solution in original post

1 REPLY 1
ReneMoawad
Resolver III
Resolver III

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)

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.