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
carogomez
Helper I
Helper I

DAX in power query

HI!!

 

I`m having problems formulating in power bi query:

I want to add a column with 1 and 0, where 1 indicates the date is before from today and 0 if it is greated than today.

 

But there is an error and I don't understand why:

Can you tell me what i'm doing wrong?

Thanks

 

carogomez_1-1607795979024.png

 

1 ACCEPTED SOLUTION

@carogomez , Power Query is also extremely strick with data type in calculation, if the column [fech] is of type Date, the formula should be what I wrote above; if DateTime, the formula should be this accordingly,

if [fech]<=DateTime.LocalNow() then 1 else 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

7 REPLIES 7
mahoneypat
Employee
Employee

FYI that you can click in the cell next to the word Error to see the error (not on the word).  In this case, you are comparing DateTime with Date which gives error.  You need to convert your column to Date first, or, if you need DateTime, you need to remove DateTime.Date from DateTime.LocalNow() or add DateTime.Date around your column.

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Fowmy
Super User
Super User

@carogomez 

Check the Data Type of the following column, it has to be Date/Time, if not right-click and change it to Date/Time before adding the new column, also check if any error exists. 

[fechainicio]

 

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

 

"Fechainicio": I changed the column type to Date/time and the error persist. 

What else is happenning, can`t understand.

Thank you very much for your fast reply.

 

carogomez_0-1607803046934.png

 

 

 

@carogomez , Power Query is also extremely strick with data type in calculation, if the column [fech] is of type Date, the formula should be what I wrote above; if DateTime, the formula should be this accordingly,

if [fech]<=DateTime.LocalNow() then 1 else 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Perfect, I applied all you told me, but is still persisting the error:

carogomez_0-1607872081782.png

I made click in the error and this was the message.

CNENFRNL
Community Champion
Community Champion

Hi, @carogomez , power query is case-sensitive and there's a specific way to obtain today's date. You might want to try this formula

if [fech]<=DateTime.Date(DateTime.LocalNow()) then 1 else 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thank for your help. Now the formula is ok for power query but now their is an error in the columns:

carogomez_0-1607798364402.png

 

carogomez_1-1607798388984.png

 

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.