Forum Discussion
How to fill out data with missing dates
- 3 years ago
Hello!
It sounds like you need to create a calendar table in Power BI to ensure that you have a continuous date range for all your products. This will allow you to fill in the missing dates with '0' value as needed. Here's a step-by-step guide to achieve this:
Create a calendar table:
First, you need to create a separate calendar table that covers the entire date range of your data. You can create this table in Power BI using DAX.a. Go to the 'Home' tab and click on 'Enter Data'.
b. Name the new table 'Calendar' and click 'Load'.
c. Select the 'Calendar' table and go to the 'Modeling' tab. Click on 'New Table'.
d. Enter the following DAX expression (adjust the date range accordingly):DAX :
Calendar =
CALENDAR (DATE (2017, 1, 1), DATE (2021, 12, 31))Create relationships between tables:
Now, you need to create a relationship between the calendar table and your sales data table.a. Go to the 'Model' view and drag the 'Date' column from the Calendar table to the corresponding 'Date' column in your sales data table. This will create a relationship between the two tables.
Update your measures:
Modify your existing measures to use the new calendar table instead of the date column from the sales data table.For example, if you have a measure like:
DAX : Total Sales = SUM (Sales[SalesAmount])
Update it to:
Total Sales =
CALCULATE (
SUM (Sales[SalesAmount]),
USERELATIONSHIP (Sales[Date], Calendar[Date])
)Fill in missing dates with '0' value:
To fill in the missing dates with a '0' value, you can use the following measure:DAX : Sales with Missing Dates =
IF (
ISBLANK ([Total Sales]),
0,
[Total Sales]
)Now, you can use the 'Sales with Missing Dates' measure in your visuals and tables. This will ensure that even if a product has missing dates, it will display '0' value for those dates, and the visuals won't break when filtering by specific products.
Remember to update all your other measures to use the Calendar[Date] instead of Sales[Date], and your visuals should work as expected.
Hello!
It sounds like you need to create a calendar table in Power BI to ensure that you have a continuous date range for all your products. This will allow you to fill in the missing dates with '0' value as needed. Here's a step-by-step guide to achieve this:
Create a calendar table:
First, you need to create a separate calendar table that covers the entire date range of your data. You can create this table in Power BI using DAX.
a. Go to the 'Home' tab and click on 'Enter Data'.
b. Name the new table 'Calendar' and click 'Load'.
c. Select the 'Calendar' table and go to the 'Modeling' tab. Click on 'New Table'.
d. Enter the following DAX expression (adjust the date range accordingly):
DAX :
Calendar =
CALENDAR (DATE (2017, 1, 1), DATE (2021, 12, 31))
Create relationships between tables:
Now, you need to create a relationship between the calendar table and your sales data table.
a. Go to the 'Model' view and drag the 'Date' column from the Calendar table to the corresponding 'Date' column in your sales data table. This will create a relationship between the two tables.
Update your measures:
Modify your existing measures to use the new calendar table instead of the date column from the sales data table.
For example, if you have a measure like:
DAX : Total Sales = SUM (Sales[SalesAmount])
Update it to:
Total Sales =
CALCULATE (
SUM (Sales[SalesAmount]),
USERELATIONSHIP (Sales[Date], Calendar[Date])
)
Fill in missing dates with '0' value:
To fill in the missing dates with a '0' value, you can use the following measure:
DAX : Sales with Missing Dates =
IF (
ISBLANK ([Total Sales]),
0,
[Total Sales]
)
Now, you can use the 'Sales with Missing Dates' measure in your visuals and tables. This will ensure that even if a product has missing dates, it will display '0' value for those dates, and the visuals won't break when filtering by specific products.
Remember to update all your other measures to use the Calendar[Date] instead of Sales[Date], and your visuals should work as expected.
Thank you that's a really clear and detailed explanation!