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
Anonymous
Not applicable

DAX Measure Very Slow

Hello,

 

I have a Measure where I am calculating the number of occurences (repetitions) of a Key within 'N' Days (Based on Parameter Selection from Slicer) before & after the date mentioned in each row. Also, the occurence needs to be counted only if the Net Price is either lower by 10% or more, or higher than 10% or more.

 

I have the following meaasure, but it takes 6-8 minutes for computing every time, but I am looking for a quicker result. Please guide.

 

Thanks in Advance..!

 

DAX

 

Count =

 

VAR DT1 = MIN(Data[Created On]) - Parameter[Parameter Value]

VAR DT2 = MIN(Data[Created On]) + Parameter[Parameter Value]

 

RETURN

 

CALCULATE(

    COUNT(Data[Key]),

    FILTER(

        ALL(Data),

        AND(

            Data[Created On] >= DT1,

            AND(

                Data[Created On] <= DT2,

                AND(

                    Data[Key] = SELECTEDVALUE(Data[Key])

                    ,

                    OR(

                        Data[Net Price] <= (SELECTEDVALUE(Data[Net Price]) * 0.90),

                        Data[Net Price] >= (SELECTEDVALUE(Data[Net Price]) * 1.10)

                    )

                )

            )

        )

    )

)

2 REPLIES 2
Fowmy
Super User
Super User

@Anonymous 

Not sure about your data model the table column and row count, anyway, try your measure this way:

Count =
VAR DT1 =   MIN ( Data[Created On] ) - Parameter[Parameter Value]
VAR DT2 =   MIN ( Data[Created On] ) + Parameter[Parameter Value]
VAR DTKY = SELECTEDVALUE ( Data[Key]
VAR MINNETPRICE = SELECTEDVALUE ( Data[Net Price] ) * 0.90
VAR MAXNETPRICE = SELECTEDVALUE ( Data[Net Price] ) * 1.10 

RETURN
CALCULATE (
    COUNT ( Data[Key] ),
    FILTER (
        ALL ( Data[Created On] , Data[Key] , Data[Net Price] ),
        Data[Created On] >= DT1 && Data[Created On] <= DT2 && Data[Key] =  DTKY  && (Data[Net Price] <= MINNETPRICE || Data[Net Price] >= MAXNETPRICE)
    )
)

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Greg_Deckler
Super User
Super User

@Anonymous Would need to understand your data better. I wrote some blog articles on performance. One of the keys would be to eliminate as many rows as possible as early as possible within your calculation. 

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-1/ba-p/976275

https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-2/ba-p/976813

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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