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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
RossBateman96
Regular Visitor

Finding closest dates that are filtered by another column

Hello

I've added an example of the table below:

RossBateman96_0-1661422059956.png

 

Im trying to populate another table with meter readings closest to to the last day of the month and split by meter. I managed to do this on excel (without filtering by meter) by using the index and min functions. 

RossBateman96_1-1661422118968.png

 

Does anyone know of a formula that is capable of doing this? The end aim is to get the difference in every meter reading from month to month.

 

Thanks in advance, Ross

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @RossBateman96 

 

Assume the first table is called Table1 and the second table is Table2, you can add two calculated columns to the second table with below DAX. 

A-MAIN =
MAXX (
    TOPN (
        1,
        FILTER ( Table1, Table1[Meter] = "A-MAIN" ),
        ABS ( DATEDIFF ( Table2[MonthEnd], Table1[Date], DAY ) ), ASC
    ),
    Table1[Date]
)
B-MAIN = 
MAXX (
    TOPN (
        1,
        FILTER ( Table1, Table1[Meter] = "B-MAIN" ),
        ABS ( DATEDIFF ( Table2[MonthEnd], Table1[Date], DAY ) ), ASC
    ),
    Table1[Date]
)

vjingzhang_0-1661766094625.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @RossBateman96 

 

Assume the first table is called Table1 and the second table is Table2, you can add two calculated columns to the second table with below DAX. 

A-MAIN =
MAXX (
    TOPN (
        1,
        FILTER ( Table1, Table1[Meter] = "A-MAIN" ),
        ABS ( DATEDIFF ( Table2[MonthEnd], Table1[Date], DAY ) ), ASC
    ),
    Table1[Date]
)
B-MAIN = 
MAXX (
    TOPN (
        1,
        FILTER ( Table1, Table1[Meter] = "B-MAIN" ),
        ABS ( DATEDIFF ( Table2[MonthEnd], Table1[Date], DAY ) ), ASC
    ),
    Table1[Date]
)

vjingzhang_0-1661766094625.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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