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

If Condition: Date comparison from two different tables

Hello,

 

I have the following tables(as a preview):

 

Table A:

 

ID     InProgressDate    SolvedDate

1       2/5/2018                2/7/2018

2       2/6/2018               2/8/2018

3       4/6/2018                4/9/2018

Table B:

 

Phase     Start Date            End Date

Phase1       2/01/2018           2/10/2018

Phase2        04/02/2018           05/10/2018

 

What I want is to make a visual table to see table A Columns but with another column stating in which Phase each ID situates based on InProgress or SolvedDate(If InProgressDate or  SolvedDate are between  Start Date & End Date :

 

ID     InProgressDate    SolvedDate     Phase

1       2/5/2018                2/7/2018        Phase1

2       2/6/2018               2/8/2018         Phase1

3       4/6/2018                4/9/2018        Phase2

 

 

Can someone help me? I can't find a solution.. 😞 

Thank you in advance!

 

 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

I would think that your column would go something along the lines of:

 

Column = 
MAXX(FILTER(ALL('Table B'),'Table B'[Start Date]>=[InProgressDate] && 'Table B'[End Date]<=[SolvedDate]),[Phase])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

You can add column to your Table A like so:

 

let
    Source = TableA,
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Table.SelectRows(TableB, (tblB) => tblB[StartDate] <= _[InProgressDate] and tblB[EndDate] >= _[SolvedDate])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Phase"}, {"Phase"})
in
    #"Expanded Custom"

code in "Add-column"-dialogue:

 

 

image.png

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

I would think that your column would go something along the lines of:

 

Column = 
MAXX(FILTER(ALL('Table B'),'Table B'[Start Date]>=[InProgressDate] && 'Table B'[End Date]<=[SolvedDate]),[Phase])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler, it did the job! 😄 

@Greg_Deckler Any idea if I can do this from the query editor and not from DAX? Is there any method?

That would be a question for @ImkeF.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@ImkeF can you please help?

You can add column to your Table A like so:

 

let
    Source = TableA,
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Table.SelectRows(TableB, (tblB) => tblB[StartDate] <= _[InProgressDate] and tblB[EndDate] >= _[SolvedDate])),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Phase"}, {"Phase"})
in
    #"Expanded Custom"

code in "Add-column"-dialogue:

 

 

image.png

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thank you a lot for the help @ImkeF! It worked! 🙂 

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.