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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

if date1 = date2 then shows as blank else shows date2

Hi,

Need some help in bulding the logic below.

I have 2 tables related by ID. When showing on a table format, I want a new column showing if DATE1 = DATE 2, then shows as blank, else shows DATE 2.

 

This is what I have today:

 
IDDate 1 (Table 1)Date 2 (Table 2)
101/02/202004/02/2020
202/02/202002/02/2020
303/02/202003/02/2020
404/02/202007/02/2020

 

And this is what I need:

 

IDDate 1 New Column
101/02/202004/02/2020
202/02/2020 
303/02/2020 
404/02/202007/02/2020

 

Can somebody help me? Maybe a DAX formula with IF statemnt.

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

If you have a table visual with ID and Date1 as columns, you could add a measure like this

 

Date2 Match = var date1value = selectedvalue(Table1[Date1])

var date2value = min(Table2[Date2]) //this assumes there is a single value in Table2 for this ID value

return if(datevalue1=datevalue2, blank(), datevalue2)

 

If there are multiple date values in Table2 for each ID, a different measure is needed and you'll need to describe the logic needed to get the desired Date2 value for comparison.

 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
Anonymous
Not applicable

If the two tables are related by ID and this is 1-to-1 relationship, then you should merge them into one table in Power Query. Then it'll be easy to do what you want. Also in Power Query.

Best
D
mahoneypat
Microsoft Employee
Microsoft Employee

If you have a table visual with ID and Date1 as columns, you could add a measure like this

 

Date2 Match = var date1value = selectedvalue(Table1[Date1])

var date2value = min(Table2[Date2]) //this assumes there is a single value in Table2 for this ID value

return if(datevalue1=datevalue2, blank(), datevalue2)

 

If there are multiple date values in Table2 for each ID, a different measure is needed and you'll need to describe the logic needed to get the desired Date2 value for comparison.

 

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi @mahoneypat it worked like a charm :). Thank you a bunch.

 

In the same table I have also Amount 1 and Amount 2.

Is there any way I can create enrich these variables that if Date2value is blank then Amount2 is blank also?

 

I tried to use these variables you mentioned but couldn't do it.

Yes.  Just reference the Date2 measure as follows:

 

Amount2 Measure = if(isblank([Date2Measure]), blank(), [Amount2 Measure])

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Greg_Deckler
Super User
Super User

Should be:

 

New Column =
  VAR __Date1 = 'Table1'[Date 1]
  VAR __Date2 = MAXX(RELATEDTABLE('Table 2'),[Date 2])
  IF(
    __Date1 = __Date2,__Date2,BLANK()
  )
    

 

You might also have luck with:

New Column =
  VAR __Date1 = 'Table1'[Date 1]
  VAR __Date2 = MAXX(FILTER('Table 2','Table 2'[ID] = 'Table 1'[ID]),[Date 2])
  IF(
    __Date1 = __Date2,__Date2,BLANK()
  )

 

Really going to depend on the data in your tables and their relationship to one another but you have left out some of those details.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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