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
dss25
New Member

MINX with multiple conditions

hi,

I have a table that i am trying to get the date from the previous row. To make it work properly I created an index column. This index column is responsible to classify the information, based on the id, event and date1. 

Here's an example:

 

dss25_0-1725559729475.png

 

This is how it should work, but the datefromprevious is returning the same date for both rows.

like this:

 

dss25_1-1725559764954.png

 

I'm trying to add one more condition in this code, but the "Filter" function only allows me to work with 2 conditions.

I tried to use Calculate function, but it seems to have some kind of incompatibility with MINX function and I can't filter either.

this is the code:

NewColumn = MINX(FILTER(Table[ID] = EARLIER(Table[ID]) && [Index] = EARLIER([Index])-1), [Date1])
 
How can I use multiple filters in this case?
1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @dss25 ,

 

Try this calculated column:

 

DATEFORMPREVIOUS = 
VAR __cur_id = 'Table'[ID]
VAR __cur_event = 'Table'[EVENT]
VAR __cur_index = 'Table'[INDEX]
VAR __result =
    CALCULATE (
        MIN ( 'Table'[DATE1] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ID] = __cur_id
                && 'Table'[EVENT] = __cur_event
                && 'Table'[INDEX] = __cur_index - 1
        )
    )
RETURN
    __result

 

vcgaomsft_0-1725587139319.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

If for an ID and event combination, there can never be a duplicate entry in the Date1 column, then the Index column is not required.  Try this calculated column formula

Previous date  = calculate(max(Data[Date1]),filter(Data,Data[id]=earlier(Data[id])&&data[event]=earlier(data[event])&&data[date1]<earlier(data[date1])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-cgao-msft
Community Support
Community Support

Hi @dss25 ,

 

Try this calculated column:

 

DATEFORMPREVIOUS = 
VAR __cur_id = 'Table'[ID]
VAR __cur_event = 'Table'[EVENT]
VAR __cur_index = 'Table'[INDEX]
VAR __result =
    CALCULATE (
        MIN ( 'Table'[DATE1] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ID] = __cur_id
                && 'Table'[EVENT] = __cur_event
                && 'Table'[INDEX] = __cur_index - 1
        )
    )
RETURN
    __result

 

vcgaomsft_0-1725587139319.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thank you so much! This solved my problem!

Jihwan_Kim
Super User
Super User

Hi,


Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1725560384085.png

 

OFFSET function (DAX) - DAX | Microsoft Learn

Expected result CC = 
MAXX (
    OFFSET (
        -1,
        'Table',
        ORDERBY ( 'Table'[INDEX], ASC ),
        ,
        PARTITIONBY ( 'Table'[EVENT] ),
        MATCHBY ( 'Table'[DATE1], 'Table'[EVENT], 'Table'[ID], 'Table'[INDEX] )
    ),
    'Table'[DATE1]
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Thank you for your help!

I'm trying to apply this solution into the real case, but it seems to not work because the "relation" parameter from offset has duplicated lines. How can I send you the file back with a table that is more like the real case?

 

Hi,

Thank you for your message, and you can share the link of the file (Onedrive, Dropbox, Googledrive, others...).

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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.