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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
EaglesTony
Post Prodigy
Post Prodigy

How do I find the correct column based off a date

I have the following table:

EaglesTony_0-1738868396968.png

 

Based off this I have another table(i.e. table2):

Key    StartDate    EndDate

ABC    1/3/2024   4/1/2024

DEF     2/1/2024   4/1/2024

HIJ      4/4/2025   7/1/2024

 

I need to get the value from the first table where the StartDate falls into it and EndDate, so I would end up on table2:

Key    StartDate    EndDate         PIBasedOnStartDate         PIBasedOnEndDate

ABC    1/3/2024   4/1/2024        2024-PI1                           2024-PI2

DEF     2/1/2024   4/1/2024       2024-PI1                            2024-PI2

HIJ      4/4/2025    7/1/2024      2025-PI2                            2025-PI2

 

I need this to get a final table as 

Key    PIFallsIn

ABC   2024-PI1

ABC   2024-PI2

DEF   2024-PI1

DEF   2024-PI2

HIJ     2025-PI2

Thanks,

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @EaglesTony 

 

Please try this:

First of all, add 2 calculated columns in the Table 2:

PIBasedOnStartDate =
VAR _vtable =
    FILTER (
        CROSSJOIN (
            SELECTCOLUMNS ( 'Table 2', "_StartDate", 'Table 2'[StartDate] ),
            'Table'
        ),
        [_StartDate] >= 'Table'[StartDate]
            && [_StartDate] <= 'Table'[EndDate]
    )
RETURN
    MAXX ( FILTER ( _vtable, [_StartDate] = 'Table 2'[StartDate] ), [PI] )
PIBasedOnStartDate =
VAR _vtable =
    FILTER (
        CROSSJOIN (
            SELECTCOLUMNS ( 'Table 2', "_StartDate", 'Table 2'[StartDate] ),
            'Table'
        ),
        [_StartDate] >= 'Table'[StartDate]
            && [_StartDate] <= 'Table'[EndDate]
    )
RETURN
    MAXX ( FILTER ( _vtable, [_StartDate] = 'Table 2'[StartDate] ), [PI] )

The result:

vzhengdxumsft_0-1738894042824.png

Then add a Calculated table:

Outcome =
SUMMARIZE (
    UNION (
        SELECTCOLUMNS (
            'Table 2',
            "Key", 'Table 2'[Key],
            "PIFallsIn", 'Table 2'[PIBasedOnStartDate]
        ),
        SELECTCOLUMNS (
            'Table 2',
            "Key", 'Table 2'[Key],
            "PIFallsIn", 'Table 2'[PIBasedOnEndDate]
        )
    ),
    [Key],
    [PIFallsIn]
)

The result is as follow:

vzhengdxumsft_1-1738894081654.png

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Cannot undestand how you generated the last 2 columns as seen in the second table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @EaglesTony 

 

Please try this:

First of all, add 2 calculated columns in the Table 2:

PIBasedOnStartDate =
VAR _vtable =
    FILTER (
        CROSSJOIN (
            SELECTCOLUMNS ( 'Table 2', "_StartDate", 'Table 2'[StartDate] ),
            'Table'
        ),
        [_StartDate] >= 'Table'[StartDate]
            && [_StartDate] <= 'Table'[EndDate]
    )
RETURN
    MAXX ( FILTER ( _vtable, [_StartDate] = 'Table 2'[StartDate] ), [PI] )
PIBasedOnStartDate =
VAR _vtable =
    FILTER (
        CROSSJOIN (
            SELECTCOLUMNS ( 'Table 2', "_StartDate", 'Table 2'[StartDate] ),
            'Table'
        ),
        [_StartDate] >= 'Table'[StartDate]
            && [_StartDate] <= 'Table'[EndDate]
    )
RETURN
    MAXX ( FILTER ( _vtable, [_StartDate] = 'Table 2'[StartDate] ), [PI] )

The result:

vzhengdxumsft_0-1738894042824.png

Then add a Calculated table:

Outcome =
SUMMARIZE (
    UNION (
        SELECTCOLUMNS (
            'Table 2',
            "Key", 'Table 2'[Key],
            "PIFallsIn", 'Table 2'[PIBasedOnStartDate]
        ),
        SELECTCOLUMNS (
            'Table 2',
            "Key", 'Table 2'[Key],
            "PIFallsIn", 'Table 2'[PIBasedOnEndDate]
        )
    ),
    [Key],
    [PIFallsIn]
)

The result is as follow:

vzhengdxumsft_1-1738894081654.png

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

It looks like the 2 calculated column syntax look the same ????

Anonymous
Not applicable

Hi @EaglesTony 

 

Sorry for the late reply, it was my fault that I accidentally copied the same calculated column.

It should be these 2 calculated columns:

PIBasedOnStartDate =
VAR _vtable =
    FILTER (
        CROSSJOIN (
            SELECTCOLUMNS ( 'Table 2', "_StartDate", 'Table 2'[StartDate] ),
            'Table'
        ),
        [_StartDate] >= 'Table'[StartDate]
            && [_StartDate] <= 'Table'[EndDate]
    )
RETURN
    MAXX ( FILTER ( _vtable, [_StartDate] = 'Table 2'[StartDate] ), [PI] )
PIBasedOnEndDate =
VAR _vtable =
    FILTER (
        CROSSJOIN (
            SELECTCOLUMNS ( 'Table 2', "_EndDate", 'Table 2'[EndDate] ),
            'Table'
        ),
        [_EndDate] >= 'Table'[StartDate]
            && [_EndDate] <= 'Table'[EndDate]
    )
RETURN
    MAXX ( FILTER ( _vtable, [_EndDate] = 'Table 2'[EndDate] ), [PI] )

 

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parry2k
Super User
Super User

@EaglesTony your post doesn't explain what is the logic to calculate PI values?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I actually did this in DAX, but thanks.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors