cancel
Showing results for 
Search instead for 
Did you mean: 
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

View solution in original post

7 REPLIES 7
mahoneypat
Super User IV
Super User IV

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 IV
Super User IV

@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


Blog - Data Visualization

Website   YouTube    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

View solution in original post

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
Super User III
Super User III

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

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
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors