cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Pete230
Helper II
Helper II

Compare Date Column with current date

Hi guys,

 

I'm struggeling with the following: I would like to compare a date colum (last day of month) with the current month, if the current month is less or equal as the date colum then the numbers of the next column should be displayed, otherwise there should be a 0.

So I would like to see all the numbers until mai and for the following months just a 0.

 

Pete230_0-1685004618881.png

I guess it's not to hard, but I can not figure it out right now, any ideas will be appreciated.

 

Thank you and regards

Pete

1 ACCEPTED SOLUTION
JavidM
New Member

Alternatively, you can use the following M code without converting the Date column into datetime format:

= Table.AddColumn(#"Changed Type", "Custom", each if [Date] > DateTime.Date(Date.EndOfMonth(DateTime.LocalNow())) then 0 else [Amount])

 

Hope this helps!

View solution in original post

5 REPLIES 5
JavidM
New Member

Alternatively, you can use the following M code without converting the Date column into datetime format:

= Table.AddColumn(#"Changed Type", "Custom", each if [Date] > DateTime.Date(Date.EndOfMonth(DateTime.LocalNow())) then 0 else [Amount])

 

Hope this helps!

Works perfectly fine, thanks a lot!

Cheers
Pete

JavidM
New Member

You can use the following M code:

= Table.AddColumn(#"Changed Type1", "Custom", each if [Date] > Date.EndOfMonth(DateTime.LocalNow()) then 0 else [Amount])

Bear in mind that you have to convert the date column to datetime format before applying the function.

Pete230
Helper II
Helper II

Thank you for your answer. I would like to create the same in M (Power Querry) not in DAX, I wasnt pricise on that. Do you know that as well?

 

Thank you!

JavidM
New Member

Hi there,

 

If I understood your question correctly, you want to show the amounts up until the current month (May 2023) leaving zeros for all consecutive months. So, when we are in June 2023, the data will appear for the respective month only leaving July and future months as 0.

 

You can try using the following DAX function:

New Column =
IF('Table'[Date].[Date] > EOMONTH(TODAY(), 0), 0, 'Table'[Amount])
 
Let me know if it worked! Thanks!

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors