Forum Discussion

sumsar10171's avatar
sumsar10171
Frequent Visitor
3 years ago

DAX expression for finding the new row for a given customer

Hi,

 

I'm trying to write a dax expression which will give me a new column for my table "meetings".

It's suppose to fetch the meeting type for the next meeting for the client.

 

Current table:

IDCustomerIDDateType
112023-02-01Startup
222023-02-01Retention
332023-02-01Startup
422023-02-05Support
512023-02-05Adjustment

 

What I'm looking for:

IDCustomerIDDateTypeNext meeting type
112023-02-01StartupAdjustment
222023-02-01RetentionSupport
332023-02-01Startup 
422023-02-05Support 
512023-02-05Adjustment 

 

 

 

5 Replies

  • You can create a column like

    Next meeting type = 
    VAR NextMeeting = OFFSET(
    	1,
    	'Table',
    	ORDERBY( 'Table'[Date], ASC),
    	PARTITIONBY( 'Table'[CustomerID])
    )
    VAR MeetingType = SELECTCOLUMNS( NextMeeting, "Type", 'Table'[Type])
    RETURN MeetingType 

    If it complains that there may be duplicate rows you'll need to go into the modelling view, select the table and choose ID as the key column.

  • hi sumsar10171 

    try like:

    Column = 
    MINX(
        TOPN(
            1,
            FILTER(
                TableName,
                TableName[CustomerID] = EARLIER(TableName[CustomerID])            
                    &&TableName[Date] > EARLIER(TableName[Date])      
            ),
            TableName[Date],
            DESC
        ),
        TableName[Type]
    )

    it worked like:

     

    • sumsar10171's avatar
      sumsar10171
      Frequent Visitor

      It doesn't account for customers with more then two meetings.

      In that case it will simply take the type of the latest meeting and apply to all previous meetings

  • smpa01's avatar
    smpa01
    Icon for Community Champion rankCommunity Champion

    sumsar10171  with new DAX OFFSET; PFA

    Measure = 
    CALCULATE (
        [__type],
        OFFSET (
            1,
            DISTINCT ( ALL ( tbl ) ),
            ORDERBY ( tbl[Date], ASC ),
            KEEP,
            PARTITIONBY ( tbl[CustomerID] )
        )
    )

     

     

     

     

    • sumsar10171's avatar
      sumsar10171
      Frequent Visitor

      Is it possible to write this as a column?