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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
IzuruWi
Frequent Visitor

Optimize existing DAX measure

Hi All, Anyone can help me to optimize the below DAX Measure? It takes more time and affects the visualization loading. I have copied the text in the DAX measure below.

Thanks you very much.

 

IzuruWi_0-1666584825496.png

 

 

MEASURE FACT_CONSOL_BALANCE_OL[Measure 4] =
SWITCH (
TRUE (),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "1 - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
CONTAINS (
DIM_ANALYTIC_STRUCT_ACCOUNT,
DIM_ANALYTIC_STRUCT_ACCOUNT[STRUCTURE_NODE (groups)], "2 - NON - CURRENT ASSETS"
), SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ),
SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) * -1
)
1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @IzuruWi ,
I am not used to using the contains function, but everything else looks like it should load fairly fast.
In your case, I would recommed to add a "Sign"-column to your Accounts-table that shows either 1 or -1 according to the logic in your measure code.
Then you can just do a:
M =
SUMX (
VALUES ( DIM_ANALYTIC_STRUCT_ACCOUNT[YourNewSignColumn] ),
CALCULATE ( SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) ) * DIM_ANALYTIC_STRUCT_ACCOUNT[YourNewSignColumn]
)


Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
ImkeF
Super User
Super User

Hi @IzuruWi ,
I am not used to using the contains function, but everything else looks like it should load fairly fast.
In your case, I would recommed to add a "Sign"-column to your Accounts-table that shows either 1 or -1 according to the logic in your measure code.
Then you can just do a:
M =
SUMX (
VALUES ( DIM_ANALYTIC_STRUCT_ACCOUNT[YourNewSignColumn] ),
CALCULATE ( SUM ( FACT_CONSOL_BALANCE_OL[BALANCE] ) ) * DIM_ANALYTIC_STRUCT_ACCOUNT[YourNewSignColumn]
)


Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

IzuruWi
Frequent Visitor

I have managed to do it in a little different way.. Thank you very much for the support @ImkeF 

Another possibility is to calculate the pieces separately.

CALCULATE (
    SUM ( FACT_OL[BALANCE] ),
    "1 - CURRENT ASSETS" IN VALUES ( DIM_ACCOUNT[STRUCTURE] )
)
-
CALCULATE (
    SUM ( FACT_OL[BALANCE] ),
    "2 - NON - CURRENT ASSETS" IN VALUES ( DIM_ACCOUNT[STRUCTURE] )
)

(Table and column names shortened for readability.)

Thank you very much @AlexisOlson. For the time being I have done it little differently. However managed get it done.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors