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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Khomotjo
Helper I
Helper I

Date Function Error

Hello Evveryone, I am trying to construct a date using the Date function. My data looks like this :

 

Khomotjo_0-1737556358154.png

My calculated coloumn looks like this : 

 

WF_Finalised = DATE (StockMovements[P9_WhsWorkFlowFinalisedDateYear],StockMovements[Month_Number],StockMovements[P9_WhsWorkFlowFinalisedDateDay])

 

I am getting below error , I have confirmed I do not have any blanks in the year/month and day columns :

Khomotjo_1-1737556423271.png

I am using direct query in BI. There are no cyclic dependecies. The only other calculated coloumn in the month is the month date which I calculated from the month name using :

 

MonthNumber = SWITCH(
    TRUE(),
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "January", 1,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "February", 2,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "March", 3,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "April", 4,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "May", 5,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "June", 6,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth]= "July", 7,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "August", 8,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "September", 9,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "October", 10,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "November", 11,
    StockMovements[P9_WhsWorkFlowFinalisedDateMonth] = "December", 12,
    BLANK()
)
1 ACCEPTED SOLUTION

Hi @Khomotjo  - Yes, you can create a new column in Power BI using DAX that extracts only the date part from a date-time column without using DATE() or formatting it directly from the toolbar. You can use the TRUNC function in DAX.

 

Take a new column 

DateOnly = TRUNC('TableName'[DateTimeColumn])





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

9 REPLIES 9
v-junyant-msft
Community Support
Community Support

Hi @Khomotjo ,

Thanks for rajendraongole1's reply!
And @Khomotjo , The document mentions that DATE function is not supported for use in DirectQuery mode when used in calculated columns:
https://learn.microsoft.com/en-us/dax/date-function-dax#remarks 

In addition, the method provided by rajendraongole1 is a measure. When the measure is placed in a visual object, it will be affected by the context and the returned results will be different. When you place the measure directly in the visual object without other fields, it will select the maximum value each of the column in the Year, Month, and Day columns and form the date instead of returning the maximum value after the date is formed. 

vjunyantmsft_0-1737596243250.png

You can refer to the following example:

Measure = 
DATE(
    MAX('Table_1'[Year]),
    MAX('Table_1'[Month]),
    MAX('Table_1'[Day])
)

vjunyantmsft_1-1737596591271.png

If you want to get the maximum date after each row of data is combined into a date, you can add another measure:

Max_Date = MAXX(ALL(Table_1), [Measure])

vjunyantmsft_2-1737598861551.png

 

Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

rajendraongole1
Super User
Super User

Hi @Khomotjo  - Can you please verify that the StockMovements[P9_WhsWorkFlowFinalisedDateYear], StockMovements[Month_Number], and StockMovements[P9_WhsWorkFlowFinalisedDateDay] columns are of a numeric data type. The DATE function requires all arguments to be numbers.

If any of these columns are in text format, convert them to numbers using the VALUE function.

In DirectQuery mode, calculated columns might encounter limitations depending on the underlying data source or query structure.

can you also create measure calculation

TestDateMeasure =
DATE(
MAX(StockMovements[P9_WhsWorkFlowFinalisedDateYear]),
MAX(StockMovements[Month_Number]),
MAX(StockMovements[P9_WhsWorkFlowFinalisedDateDay])
)

 

If the measure works, the issue might be related to calculated column restrictions in DirectQuery.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thanks @rajendraongole1 

 

I ve verified that all  columns are whole numbers :

Khomotjo_0-1737562637447.png

The above measure works

@rajendraongole1  I just noticed that this measure returns  31 December 2025 which is incorrect. It seems that the measure caculates the maximum date in the current year. The max date is 22 January 2025.

 

Khomotjo_1-1737562934894.png

 

Hi @Khomotjo  - can you please change the Max to MAXX as like below measure.

TestDateMeasure =
DATE(
MAXX(StockMovements, StockMovements[P9_WhsWorkFlowFinalisedDateYear]),
MAXX(StockMovements, StockMovements[Month_Number]),
MAXX(StockMovements, StockMovements[P9_WhsWorkFlowFinalisedDateDay])
)

 

still if max is giving trouble , try with SELECTEDVALUE function. 

I hope this works. please check





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thanks @rajendraongole1 @v-junyant-msft  I am trying to get one date for each of the multiple date entries in the data. For example on the 22 January I might have 3 orders finalised at 11:00, 12:00 and 13:00. The data will will show all 3 with their respective date time records.  I  want to calculate the total orders finalised on the 22 January, the issue is the model considers  these 3 as separate because of the time. I tried to format the date from the tool bar( change to short date) but when I pull the table it still considers the time. It looks like this :

Khomotjo_0-1737612990128.png

I want to see only 1 entry for each of the dates in the data,

Hi @Khomotjo - To group the data by date and calculate the total orders finalized for each day (ignoring the time component), you can create a measure in Power BI that extracts only the date from the datetime field as like below:

Total Orders by Date =
CALCULATE(
COUNT('YourTable'[OrderID]),
ALLEXCEPT('YourTable', 'YourTable'[DateOnly])
)

you need to replace 'YourTable'[DateOnly] with a column created using the date part of your datetime column.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thanks @rajendraongole1   Is there another way to create a column using only the date part without using  DATE() or formating directly from the tool bar( to make the date-time a short date)?

Hi @Khomotjo  - Yes, you can create a new column in Power BI using DAX that extracts only the date part from a date-time column without using DATE() or formatting it directly from the toolbar. You can use the TRUNC function in DAX.

 

Take a new column 

DateOnly = TRUNC('TableName'[DateTimeColumn])





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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