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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
tecumseh
Helper II
Helper II

Calculated Column Get Days Between Max Date And Date

Hi,

Using PBID (March, 2024)

I created a measure to get max date from a column - works as expected
I added a calculated column to compare the measure to the order date in each row - but this is returning zero

 

Days From Max Date =
DATEDIFF( Data[Date], [Max Date], DAY )

 

What am I doing wrong?

Thanks,

-w

3 REPLIES 3
tecumseh
Helper II
Helper II

Thanks @amitchandak 

I need a calculated column. My end goal is to have something I can filter for <= 6 (0 - 6) Or the most recent 7 days. Today function seems to be problematic when refreshing in the Service not returning expected results due to time zones etc....

Thanks,

-w

Hi @tecumseh ,

I create a table as you mentioned.

vyilongmsft_0-1716873476103.png

Then I create a calculated column named MaxDate.

MaxDate = MAX('Table'[Date])

vyilongmsft_1-1716873548418.png

Also I create another calculated column.

Column = DATEDIFF('Table'[Date],'Table'[MaxDate],DAY)

vyilongmsft_2-1716873668104.png

I think the reason you're getting 0 should be that you're using Measure when calculating the max dates, so it's returning the maximum value for each row of dates, which is going to give you 0 when subtracted, but you can avoid that if you use a calculated column.

 

 

 

Best Regards

Yilong Zhou

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

amitchandak
Super User
Super User

@tecumseh , if you are trying to create a column when Max Date is Measure. You can not use a measure or slicer value in a column

 

Create a measure like

 

Averagex(data,DATEDIFF( Data[Date], [Max Date], DAY ))

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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