Create a date table

Completed

Make sure you still use the report you created titled MyFirstPowerBIModel from the previous units. You use it to create a Date table.

Create a date table

  1. Go to the Table view by selecting the Table icon in the navigation menu to the left of Power BI Desktop.

  2. From the ribbon at the top of the screen, select the Table Tools tab.

  3. Then, choose New Table from the menu at the top of the screen.

    Screenshot that shows the selection of the Table view icon button, and the location of the New Table button under the Table Tools tab.

    You see a new table called "Table" is created in the Data pane to the right of the Power BI Desktop and the formula bar opens at the top of your screen.

  4. Enter the following formula in the formula bar, then hit Enter on your keyboard:

    Date = CALENDAR(DATE(2014,1,1), DATE(2022,12,31))

    You're using two DAX functions: the CALENDAR function, which accepts the start and end data, and the DATE function, which takes the year, month, and day fields.

    For this scenario, you need to create dates from 2014 to 2021 (since we have data for those years). We can also add more fields, like Year, Month, Week, etc., to the table by using other DAX functions.

  5. In the Data pane, select the Date field in the Date table.

    Screenshot that shows the Date field selected in the date table, inside the Data pane.

  6. The Date field is in the Date/Time data type, but you need it to be the Date data type. To change it, select the Column Tools tab from the ribbon.

  7. Then, choose the Data type drop-down and select Date.

    Screenshot that shows the Date/Time data type get changed to the Date data type on the Column Tools tab.

  8. Now, you need to create a relationship between the Date and Sales tables. From the ribbon, select the Column Tools tab, and then choose Manage Relationships.

  9. The Manage Relationships dialog box opens. Select the + New relationship button.

    Screenshot that shows the Manage Relationships dialog box with the new button selected.

  10. Then, the New Relationship dialog box opens. Select Date from the top dropdown menu.

  11. Select Sales from the second dropdown menu.

  12. Highlight the Date field in both tables by multi-selecting.

  13. Then, select Save to close the New relationship dialog box.

    Screenshot that shows a Date relationship created between the Date and Sales tables, and the Ok button selected.

  14. Select the Close button to close the Manage relationships dialog box.

  15. Now, select the Report view icon in the left navigation menu to go to the Report view.

    Screenshot that shows the report icon selected to show the report view.

    The Sum of Revenue by Date chart looks different now. Let's fix that.

  16. Select the Sum of Revenue by Date visual.

  17. From the X-axis section in the Visualizations pane, select the X to remove the Date field.

    Screenshot that shows the Date field removed from the x-axis of the Sum of Revenue by Date visual inside the Visualizations pane.

  18. From the Data pane, expand the Date table.

  19. Now, drag and drop the Date field from the Date table to the X-axis section in the Visualizations pane.

  20. Select the Drill up button above the visual until the visual is on the Year level.

    Screenshot that shows the Drill up button selected until the visual shows the revenue data on the Year level.

    Now, the new Date field behavior is like it was previously.

    Since there are now two Date fields, you might be confused which one to use. To remove confusion, hide the Date field in the Sales table.

  21. From the Data pane, hover over and select the ellipses (…) to the right of the Date field in the Sales table.

  22. Then, select Hide from the options menu.

    Screenshot that shows the Date field hidden in the Sales table, inside the Data pane.

  23. Use the preceding steps to hide Country, ProductID, Zip, and ZipCountry in the Sales table as well. The only fields that should now be in the Sales table are Revenue and Units.

  24. Next, hide ZipCountry from the Geography table.

  25. Then, hide ManufacturerID from the Manufacturer table.

  26. Hide ProductID and ManufacturerID from the Product table.

Tip

It’s best practice to hide fields that are not used in your report visuals. These fields are the basis of our relationships between each table so we should not delete them.