Convert Calculated Column to DAX Measure

Can someone help me in converting the following code from a calculated column to a DAX measure so that I can use it across multiple queries. And maybe even explain the general mechanics for deriving the solution on my own?

Overlaps_A_Run = 
VAR _endDate = 'LREMerged'[Test Run End Date]
VAR _startDate = 'LREMerged'[Test Run Start Date]
VAR last =
    MAXX (
        FILTER (
            'LREMerged',
            'LREMerged'[Test Run End Date]
                < _endDate
        ),
        'LREMerged'[Test Run End Date]
    )
VAR next =
    MINX (
        FILTER (
            'LREMerged',
            'LREMerged'[Test Run Start Date]
                > _startDate
        ),
        'LREMerged'[Test Run Start Date]
    )
RETURN
    IF (
        ISBLANK ( last )
            && next > 'LREMerged'[Test Run End Date]
            || ISBLANK ( next )
                && last < 'LREMerged'[Test Run Start Date],
        0,
        IF (
            last > 'LREMerged'[Test Run Start Date]
                || next < 'LREMerged'[Test Run End Date],
            1,
            0
        )
    )

Hi @jsonify i @j, I noticed you didn’t provide a PBIX file. Providing one will help users and experts find a solution to your inquiry faster and better.

A perfect initial question includes all of the following:

  • A clear explanation of the problem you are experiencing
  • A mockup of the results you want to achieve
  • Your current work-in-progress PBIX file
  • Your underlying data file (to allow us to go into Power Query if necessary to transform your data and/or data model – often DAX questions really end up being data modeling solutions)

Check out this thread on Tools and Techniques for Providing PBIX Files with Your Forum Questions

Not completing your data may sometimes cause delay in getting an answer.

Oh my apologies. I’m not sure how I missed that part in my submission.

Here is the example file:
Overlap-Example.pbix (21.8 KB)

Hi @jsonify,

Your calculated column tells you if each run date is overlapping another run.
For instance for the Run ID 1, the results is 1 because the dates from 02/07/2019 9AM to 02/07/2019 5PM overlaps the dates of the Run ID 2.

To better show you the calculated column result, I have created a column for each variable in the formula.

Here is the measure

The only differences are that you need to use “SELECTEDVALUE” to have the value of the column and you need to add “ALLSELECTED” in the last and next variables to have access to all the table and not just the specific rows.

Here is the full solution
Overlap-Example.pbix (26.7 KB)

You can delete all the calculated columns I have created, it was just to show you the different results :wink:

I hope this solution will help you.

Best regards,
JBocher

1 Like

Hi @jsonify , did the response provided by @JBocher help you solve your query?

If not, how far did you get and what kind of help you need further?

If yes, kindly mark as solution the answer that solved your query.

Hi @jsonify, we’ve noticed that no response has been received from you since September 24.

We just want to check if you still need further help with this post? In case there won’t be any activity on it in the next few days, we’ll be tagging this post as Solved.

Thank you for your help and your explanation.

1 Like