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
darlingling520
New Member

can't calculate DATEDIFF using Max function

Hi all,

 

I'm pretty new to power bi so I would like some help on this 

 

I am trying to calculate the month difference between the max date and the selected date

I tried 2 different methods:

Method 1 using today() and it worked well 

datediff = DATEDIFF(SELECTEDVALUE(DATA[date].[date]),today(),MONTH)
 
however when I tried to use the max function replacing the today() function- my result returned to 0 
datediff2 = DATEDIFF(SELECTEDVALUE(DATA[date].[date]),max(DATA[date].[Date]),MONTH)
 
does anyone know why is my max() not returning the max date of the table?
 
thanks in advanced! 
2 ACCEPTED SOLUTIONS
Samarth_18
Community Champion
Community Champion

Hi @darlingling520 ,

You could try this:-

datediff2 = 
var max_date = calculate(max(DATA[date]),ALL(DATA[date]))
return DATEDIFF(SELECTEDVALUE(DATA[date]),max_date,MONTH)

BR,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

darlingling520
New Member

okay I already figured out myself - in order to use the max function 

i need to use maxdate= calculate(max(data[date]),all(data)); so the max date will be fixed and therefore i can use it to calculate the datediff 

View solution in original post

3 REPLIES 3
darlingling520
New Member

okay I already figured out myself - in order to use the max function 

i need to use maxdate= calculate(max(data[date]),all(data)); so the max date will be fixed and therefore i can use it to calculate the datediff 

Samarth_18
Community Champion
Community Champion

Hi @darlingling520 ,

You could try this:-

datediff2 = 
var max_date = calculate(max(DATA[date]),ALL(DATA[date]))
return DATEDIFF(SELECTEDVALUE(DATA[date]),max_date,MONTH)

BR,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

thanks so much!!

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