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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

how to make a DAX expression simpler

Hi,

I have a table of ~ 70.000 rows, which contains service actions from the past 18 months. I wrote a DAX expression to calculate for each row when the next service action for the same serial number happened. It works, but I keep running into memory allocation failures since I added it to my data model, so I am searching for an alternative way to do the same calculation in a more efficient way.

 

My current expression:

Next SA = Calculate(

    MIN('D Customer Reporting'[Work Order Created On]),

    FILTER('D Customer Reporting', 'D Customer Reporting'[Serial Number] = earlier('D Customer Reporting'[Serial Number])),

    FILTER('D Customer Reporting', 'D Customer Reporting'[Work Order Created On] > earlier('D Customer Reporting'[Work Order Completed On Date])),

    Filter('D Customer Reporting', 'D Customer Reporting'[Incident Type] in {"X", "Z", "Y"}))

 

Any idea how to do that?

thanks in advance!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 

You may try

Next SA =
MINX (
    CALCULATETABLE (
        'D Customer Reporting',
        ALLEXCEPT (
            'D Customer Reporting',
            'D Customer Reporting'[Serial Number],
            'D Customer Reporting'[Work Order Created On]
        ),
        'D Customer Reporting'[Incident Type] IN { "X", "Z", "Y" }
    ),
    'D Customer Reporting'[Work Order Created On]
)

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @Anonymous 

You may try

Next SA =
MINX (
    CALCULATETABLE (
        'D Customer Reporting',
        ALLEXCEPT (
            'D Customer Reporting',
            'D Customer Reporting'[Serial Number],
            'D Customer Reporting'[Work Order Created On]
        ),
        'D Customer Reporting'[Incident Type] IN { "X", "Z", "Y" }
    ),
    'D Customer Reporting'[Work Order Created On]
)
Greg_Deckler
Community Champion
Community Champion

@Anonymous This may or may not help. Note, you should structure your FILTER statements so that you filter out the most rows first. For example, if filtering to x y and z filters out more records rather than the date filter then that should come first.

Next SA = 
  VAR __SerialNumber = MAX('D Customer Reporting'[Serial Number])
  VAR __WorkCompleted = MAX('D Customer Reporting'[Work Order Completed On Date])
RETURN
CALCULATE(
    MIN('D Customer Reporting'[Work Order Created On]),
    FILTER('D Customer Reporting', 'D Customer Reporting'[Serial Number] = __SerialNumber) && 
    'D Customer Reporting'[Work Order Created On] > __WorkCompleted && 
    'D Customer Reporting'[Incident Type] in {"X", "Z", "Y"})
)

Another way:
Next SA = Calculate(
  VAR __SerialNumber = MAX('D Customer Reporting'[Serial Number])
  VAR __WorkCompleted = MAX('D Customer Reporting'[Work Order Completed On Date])
  VAR __Table = FILTER('D Customer Reporting', 'D Customer Reporting'[Serial Number] = __SerialNumber)
  VAR __Table1 = FILTER(__Table, [Work Order Created On] > __WorkCompleted)
  VAR __Table2 = FILTER(__Table1, [Incident Type] in {"X", "Z", "Y"})
RETURN
  MINX(__Table2, [Work Order Created On])

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.