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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
TReynolds
Helper I
Helper I

Filtering the dates in one table by the dates in another table

Good afternoon,

 

I have two separate tables in a .pbix file. The first, TABLE A, has a column of dates from 2016-01-01 to 2022-12-31 (it is complete list with 1,828 rows). The second, TABLE B, has a shorter column of dates listing the dates for New Years Day, Labor Day and Thanksgiving for 2016 to 2022. I want to create a column in TABLE A that is "yes" if the date appears in both TABLE A and TABLE B, and "no" if the date only appears in TABLE A. 

 

I've tried looking for help how to do this, and am lost. Is there a way to do this with DAX in Power BI?

 

Thank you in advance for your help. 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

If your Date table (many rows) is related with  1 to many relationship with the Holiday table (table b) you can use this calculated column:

 

 

Holiday =
IF(
    COUNTROWS(
        RELATEDTABLE( Holiday )
    ) = 0,
    "No",
    "Yes"
)

 

It simply counts the rows in the related Holiday table that have the same date as the date table. 

However, calculated columns are generally a bad practice. Can you back this up into Power Query? 

 

In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables

If you merge the table a with table b (date with holiday) as shown below:

edhans_0-1599168487385.png

Then you could expand the date column from the B table as shown here:

edhans_1-1599168551957.png

I have then added a custom column called IsHoliday with the following formula:

if [Date.1] is null then "No" else "Yes"

Then you remove the unneeded Date.1 column and now you have a clean Date table in your model with no calculated columns.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

If your Date table (many rows) is related with  1 to many relationship with the Holiday table (table b) you can use this calculated column:

 

 

Holiday =
IF(
    COUNTROWS(
        RELATEDTABLE( Holiday )
    ) = 0,
    "No",
    "Yes"
)

 

It simply counts the rows in the related Holiday table that have the same date as the date table. 

However, calculated columns are generally a bad practice. Can you back this up into Power Query? 

 

In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables

If you merge the table a with table b (date with holiday) as shown below:

edhans_0-1599168487385.png

Then you could expand the date column from the B table as shown here:

edhans_1-1599168551957.png

I have then added a custom column called IsHoliday with the following formula:

if [Date.1] is null then "No" else "Yes"

Then you remove the unneeded Date.1 column and now you have a clean Date table in your model with no calculated columns.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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