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
Anonymous
Not applicable

Calculate Date Difference between two days in same column

Hello,

i have a table with dates and index. i want to find number of dates between 2 days for same index number.

here is the example

"Results" is the output which i want.

last date(max date of an Index) of new index should be 0.  for others, it shoud calculate number of dates between row and next raw date . (i have shown the calculation in 'calculation' column which will give the 'results') i want to get the 'Resutls' column using Index and Actual Date (not the calculation column)

 

IndexActual DateResultsEx: Calculation which need to apply to get Results
18/18/20180(8/18/2018)- (8/18/2018)
18/18/20180(8/18/2018)- (8/18/2018)
18/18/20182(8/20/2018)-(8/18/2018)
18/20/201810(8/30/2018)-(8/20/2018)
18/30/20188etc
19/7/201828 
110/5/20180 
110/5/20180 
28/24/20180 
28/24/20180 
28/24/20183 
28/27/20183 
28/30/20180 
38/18/20180 
38/18/20180 
38/18/20182 
38/20/20180 

 

any help would be highly appriciated 

 

@v-juanli-msft  (you have help me for simmilar function)

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Ashish_Mathur 

this works perfectly. 

but can you please tell me how to get new index column(Index1) based on other Index?

Hi,

Good to know that.  Click on Home > Edit Queries and see the steps there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Ashish_Mathur 

thank you. but this gives a index for all raws. 
but here you got an index1 with respect to original index (separate index1 for index number 1 and separete index for index number 2)

Hi,

Look at the Partition step there.  That line has to be manually written.  It is because of this step that different index numbers are being assigned.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable


@Ashish_Mathur wrote:

Hi,

Look at the Partition step there.  That line has to be manually written.  It is because of this step that different index numbers are being assigned.


Thank you very much. i'll check

Hi ,

 

You can add the index column in query edit. 

Add column>index column>from 1

 

Dina.

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

Please use the measure below:

 

Measure =

var previndex = MAX(Table1[Index.1])-1

var prevdate = CALCULATE(MAX([Actual Date]),FILTER(ALL(Table1),[Index.1]=previndex))

Return

CALCULATE(DATEDIFF(MAX([Actual Date]),prevdate,DAY))

9.png

Best regards,

Dina Ye

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
Anonymous
Not applicable

Thank you very much for your responce.

i want to get it as a column (i'll be apply few other operations to that column later)

i tried to convert it to a column and it given me below error

 

DAX comparison operations do not support comparing values of type Text with values of type Number. Consider using the VALUE or FORMAT function to convert one of the values

 

what i want is slightly different than your answer(it needs to shift one raw)
eg: for the date 8/20/2018 value which i need is 10 (8/30/2018-8/20/2018)
ie: logic shoud be subtract the date from next raw date give the answer to same raw 

thank you

 

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.