Forum Discussion
Generate a date range to make a line between 2 dates
- Anonymous2 years ago
Hi Anonymous ,
Have you solved your problem?
If not, please try this way:
Use the DAX below to create a new table:Date table = CALENDAR(MAX('Table'[Date start]), MAX('Table'[Date end]))Then use the DAXs below to achieve your expected results:
Value = VAR A = SELECTEDVALUE('Table'[Quantity]) VAR B = CALCULATE(COUNTROWS('Date table'),ALLSELECTED('Date table')) - 1 RETURN IF( 'Date table'[Date].[Day] = 1, 0, DIVIDE(A, B) )Value2 = VAR A = SELECTEDVALUE('Table'[Quantity]) VAR B = CALCULATE(COUNTROWS('Date table'),ALLSELECTED('Date table')) - 1 VAR C = IF( 'Date table'[Date].[Day] = 1, 0, DIVIDE(A, B) ) VAR D = 'Date table'[Date].[Day] - 1 RETURN C * DBest Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You need to create a calendar table. You can create one with a template like this:
Calendar =
ADDCOLUMNS (
CALENDAR (DATE(2023, 1, 1), DATE(2024, 1, 1)),
"Year", YEAR ([Date]),
"Monthnumber", MONTH ([Date]),
"YearMonthnumber", FORMAT ([Date], "YYYY/MM"),
"YearMonthShort", FORMAT ([Date], "YYYY/mmm"),
"MonthNameShort", FORMAT ([Date], "mmm"),
"MonthNameLong", FORMAT ([Date], "mmmm"),
"DayOfWeekNumber", WEEKDAY ([Date]),
"DayOfWeek", FORMAT ([Date], "dddd"),
"DayOfWeekShort", FORMAT ([Date], "ddd"),
"Quarter", "Q" & FORMAT ([Date], "Q"),
"YearQuarter", FORMAT ([Date], "YYYY") & "/Q" & FORMAT ([Date], "Q")
)
Or just use the calendarauto function. Then create a relationship between the date field in the calendar and the date field in your data table, and use the calendar date field as the X axis on your line chart.