Forum Discussion

TReynolds's avatar
TReynolds
Icon for Helper I rankHelper I
6 years ago
Solved

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...
  • edhans's avatar
    6 years ago

    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:

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

    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.