Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
colverjustin
Frequent Visitor

DATEADD when not in date format

Hi,

 

I have a table with date and sales. However the Date is in the format YYYWW - and its a whole number, not in date format

 

Date..................Sales

202201.............10

202202............30

202203............17

etc

 

 

I want a dax format to shift the numbers along a year, so that when create a table, it shows as

 

Date..................Sales

202301.............10

202302............30

202303............17

 

 

 

Is this poss?

 

 

Thanks,

Justin

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Create a proper date table, mark it as a date table, and add a column which has, for each date, a week in the YYYYWW format. You could do this with something like

Week number =
VALUE ( YEAR ( [Date] ) & WEEKNUM ( [Date] ) )

but you may need to play around with the WEEKNUM function to make sure that it works with your definition of when a week starts.

Create a many-to-many relationship from the date table to your existing fact table, with a single direction filter where Date filters your fact table, not the other way around. Make sure to use columns from your date table in any visuals or slicers, not the column from your fact table.

You will now be able to use the time intelligence functions, e.g.

Sales last week =
CALCULATE ( SUM ( 'Table'[Sales] ), DATEADD ( 'Date'[Date], -7, DAY ) )

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

Create a proper date table, mark it as a date table, and add a column which has, for each date, a week in the YYYYWW format. You could do this with something like

Week number =
VALUE ( YEAR ( [Date] ) & WEEKNUM ( [Date] ) )

but you may need to play around with the WEEKNUM function to make sure that it works with your definition of when a week starts.

Create a many-to-many relationship from the date table to your existing fact table, with a single direction filter where Date filters your fact table, not the other way around. Make sure to use columns from your date table in any visuals or slicers, not the column from your fact table.

You will now be able to use the time intelligence functions, e.g.

Sales last week =
CALCULATE ( SUM ( 'Table'[Sales] ), DATEADD ( 'Date'[Date], -7, DAY ) )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.