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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
hari127
Frequent Visitor

$Expr0 := CallbackDataID

The following code is rewritten to eliminate the callbackdataid but it increased SE Queries and decreased SE Cache and overall performance degraded. Is callbackdataid good or bad,  Is this the correct method to eliminate callbackdataid? Why performance is degraded?

CALCULATE(
SUMX(FILTER('AccountTransactions',(RELATED(Accounts[Account Group])=1 || RELATED(Accounts[Account Group])=2)),
if(RELATED(Accounts[Account Group])=1,[Debit]-[Credit],[Credit]-[Debit])),


FILTER (
ALL ( Dates[Date] ),
Dates[Date]<= MAX ( 'Dates'[Date])
)
)

---------------new code to eliminate callbackdataid

CALCULATE(
SUMX(FILTER('AccountTransactions',RELATED(Accounts[Account Group])=1),
[Debit]-[Credit]),

FILTER (
ALL ( Dates[Date] ),
Dates[Date]<= MAX ( 'Dates'[Date])
)
)
+
CALCULATE(
SUMX(FILTER('AccountTransactions',RELATED(Accounts[Account Group])=2),
[Credit]-[Debit]),

FILTER (
ALL ( Dates[Date] ),
Dates[Date]<= MAX ( 'Dates'[Date])
)
)

6 REPLIES 6
daxer-almighty
Solution Sage
Solution Sage

If you want to have fast DAX, then never ever call a measure when iterating a fact table row by row.

 

Did you find any measure in my code?

I use THESE conventions to interpret DAX code when I read it. If you don't follow this golden standard, then you should not be surprised that people do not understand your code.

Thanks

AlexisOlson
Super User
Super User

Performance tuning is highly situational. Eliminating callbackdataid isn't always a good idea. It depends. Your second version requires iterating through 'AccountTransaction' twice instead of just once.

 

I'm not sure this will work but it may give you an idea of another path to try:

CALCULATE (
    CALCULATE ( [Debit] - [Credit], Accounts[Account Group] = 1 ) +
    CALCULATE ( [Credit] - [Debit], Accounts[Account Group] = 2 ),
    FILTER ( ALL ( Dates[Date] ), Dates[Date] <= MAX ( 'Dates'[Date] ) )
)

 

Thank you very much for the support. The following are the results using three difference versions

CALCULATE(
SUMX(FILTER('AccountTransactions',(RELATED(Accounts[Account Group])=1 || RELATED(Accounts[Account Group])=2)),
if(RELATED(Accounts[Account Group])=1,[Debit]-[Credit],[Credit]-[Debit])),


FILTER (
ALL ( Dates[Date] ),
Dates[Date]<= MAX ( 'Dates'[Date])
)
)

 

hari127_0-1622871566579.png

 

CALCULATE(
CALCULATE(
SUMX(FILTER('AccountTransactions',RELATED(Accounts[Account Group])=1),
[Debit]-[Credit])
)
+
CALCULATE(
SUMX(FILTER('AccountTransactions',RELATED(Accounts[Account Group])=2),
[Credit]-[Debit])),

FILTER (
ALL ( Dates[Date] ),
Dates[Date]<= MAX ( 'Dates'[Date])
)
)

hari127_1-1622871881683.png

 

Made changes to the model to include account group in the same table

CALCULATE(
CALCULATE(
SUMX(FILTER('AccountTransactions',[Account Group]=1),
[Debit]-[Credit])
)
+
CALCULATE(
SUMX(FILTER('AccountTransactions',[Account Group]=2),
[Credit]-[Debit])),

FILTER (
ALL ( Dates[Date] ),
Dates[Date]<= MAX ( 'Dates'[Date])
)
)

 

hari127_2-1622872598710.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors