Forum Discussion
How to emulate Line Chart from Excel to Power BI
- 5 years ago
To create a date table:
Let's say your date field in your fact table is 'FactTable'[Date]
Go into the Modeling option in the ribbon and select new table. Now type in the following code:
DateTable = VAR MinDate = MIN(FactTable[Date]) VAR MaxDate = MAX(FactTable[Date]) RETURN ADDCOLUMNS(CALENDAR(MinDate, MaxDate), "Year", YEAR([Date]), "Month Numb", MONTH([Date]), "Month", FORMAT([Date], "MMM"), "Week Number", WEEKNUM([Date]) )If you already have a date table with continuous dates covering the range of dates in your model, you can add new columns using the code for each column as above. For example,
Year = YEAR(DateTable[Date])
and
Week Number = WEEKNUM(DateTable[Date])
(apologies since my settings are in spanish. Hence the month names)
Now add a new column to this table in the ribbon and add this code:
7 Day Axis = CALCULATE(MIN(DateTable[Date]), ALLEXCEPT(DateTable, DateTable[Week Number], DateTable[Year]))Finally go to the modeling pane and join both date fields in a one-to-many relationship
You have now created a Date Table and you should use the fields from this table in your visuals, slicers, filters, measures etc. You can also now use Time Intelligence functions for your calculations using this table.
Hi PaulDBrown ,
Thanks for your reply, How have you created the WEEK NUMBER and YEAR columns in your date table as I do not have those columns in my table, I just have a date column (that too not even a complete year). The Min date is 10/2020 and MAX is 05/2021
To create a date table:
Let's say your date field in your fact table is 'FactTable'[Date]
Go into the Modeling option in the ribbon and select new table. Now type in the following code:
DateTable =
VAR MinDate = MIN(FactTable[Date])
VAR MaxDate = MAX(FactTable[Date])
RETURN
ADDCOLUMNS(CALENDAR(MinDate, MaxDate),
"Year", YEAR([Date]),
"Month Numb", MONTH([Date]),
"Month", FORMAT([Date], "MMM"),
"Week Number", WEEKNUM([Date])
)
If you already have a date table with continuous dates covering the range of dates in your model, you can add new columns using the code for each column as above. For example,
Year = YEAR(DateTable[Date])
and
Week Number = WEEKNUM(DateTable[Date])
(apologies since my settings are in spanish. Hence the month names)
Now add a new column to this table in the ribbon and add this code:
7 Day Axis = CALCULATE(MIN(DateTable[Date]), ALLEXCEPT(DateTable, DateTable[Week Number], DateTable[Year]))
Finally go to the modeling pane and join both date fields in a one-to-many relationship
You have now created a Date Table and you should use the fields from this table in your visuals, slicers, filters, measures etc. You can also now use Time Intelligence functions for your calculations using this table.