Forum Discussion

Swilson2112's avatar
Swilson2112
Frequent Visitor
4 years ago
Solved

Return a value from a table based on comparing two different fields in that same table..

I have this table: 

 

I want to compare the Invoice Date Column vs the Change Date Time Column and then return the Last Daily Change for the Change Date Time that has the closest before value.

 

In this example below:

Invoice Date:                                                               1/15/2021

Closest before Change Date and Time:                       6/14/19 15:17

Last Daily Change:                                                       .4495

 

I would like to create this as a DAX measure and insert the Last Daily Change Value into an existing visual on my dashboard that is showing Invoice#, Invoice date and some other sales information.

INVOICEINVOICE DATEPart #LINEFIELD_NAMEBEFOREAFTERDATE_CHGLast Daily ChangeChanged Date Time
225551/15/21100-1100Rate 0.4152/8/190.4152/8/19 11:09
225551/15/21100-1100Rate0.4150.492/13/190.492/13/19 6:27
225551/15/21100-1100Rate0.490.51952/27/190.51952/27/19 12:19
225551/15/21100-1100Rate0.51950.44956/14/190.44956/14/19 15:17
225551/15/21100-1100Rate0.44950.915/17/210.915/17/21 10:48
225551/15/21100-1100Rate0.911.129/22/211.129/22/21 16:30
225551/15/21100-1100Rate1.120.449512/3/211.1212/3/21 7:28
225551/15/21100-1100Rate0.44951.1212/3/211.1212/3/21 7:30
225551/15/21100-1100Rate1.120.449512/10/211.1212/10/21 6:53
225551/15/21100-1100Rate0.44950.9112/10/211.1212/10/21 7:10
225551/15/21100-1100Rate0.911.1212/10/211.1212/10/21 7:12
225551/15/21100-1100Rate1.120.9112/10/211.1212/10/21 7:18
225551/15/21100-1100Rate0.911.1212/10/211.1212/10/21 7:19
225551/15/21100-1100Rate1.120.43951/26/221.121/26/22 16:09
225551/15/21100-1100Rate0.43950.84551/26/221.121/26/22 16:42
225551/15/21100-1100Rate0.84550.911/26/221.121/26/22 16:43
225551/15/21100-1100Rate0.910.9651/26/221.121/26/22 16:44
225551/15/21100-1100Rate0.9651.021/26/221.121/26/22 16:45
225551/15/21100-1100Rate1.021.121/26/221.121/26/22 16:46
  • Hi Swilson2112 ,

     

    You may try this Measure.

    Last Daily Change Value =

    VAR max_date =

        MAXX (

            FILTER ( 'Table', 'Table'[INVOICE DATE] > 'Table'[Changed Date Time] ),

            'Table'[Changed Date Time]

        )

    RETURN

        CALCULATE (

            MAX ( 'Table'[Last Daily Change] ),

            FILTER ( 'Table', 'Table'[Changed Date Time] = max_date ),

            VALUES ( 'Table'[INVOICE] )

        )

     

    Then, the result will look like this.

     

    Also, attached the pbix file as reference.

     

    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 me know. Thanks a lot!

     

    Best Regards,

    Community Support Team _ Caiyun

1 Reply

  • v-cazheng-msft's avatar
    v-cazheng-msft
    Community Support

    Hi Swilson2112 ,

     

    You may try this Measure.

    Last Daily Change Value =

    VAR max_date =

        MAXX (

            FILTER ( 'Table', 'Table'[INVOICE DATE] > 'Table'[Changed Date Time] ),

            'Table'[Changed Date Time]

        )

    RETURN

        CALCULATE (

            MAX ( 'Table'[Last Daily Change] ),

            FILTER ( 'Table', 'Table'[Changed Date Time] = max_date ),

            VALUES ( 'Table'[INVOICE] )

        )

     

    Then, the result will look like this.

     

    Also, attached the pbix file as reference.

     

    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 me know. Thanks a lot!

     

    Best Regards,

    Community Support Team _ Caiyun