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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
AlexGallet01
Helper IV
Helper IV

Date diff

Hello,

 

I want to do a date diff between datemoyenne of my colum valeursutilisé = B and datemoyenne of my colum valeursutilisé = A.

I need do it for each valeursutilisé.

Sans titre.png

16 REPLIES 16
Anonymous
Not applicable

@AlexGallet01,

We need to verify that if you want to calculate the date difference between the current row and previous row or the date difference between the current row and the first row(ValeusrUtilise=A).

Firstly, add an index column in your table in Query Editor.
1.JPG

Secondly, if you mean the first case, create the following columns in your table.

Previousrow = CALCULATE(FIRSTNONBLANK(Table[DateMoyenne],""),FILTER(Table,Table[Index]=EARLIER(Table[Index])-1))
Datediff = IF(Table[DateMoyenne]<=Table[Previousrow],DATEDIFF(Table[DateMoyenne],Table[Previousrow],DAY)*(-1),DATEDIFF(Table[Previousrow],Table[DateMoyenne],DAY))

If you mean the second case, create the following columns in your table.

first row = CALCULATE(FIRSTNONBLANK(Table[DateMoyenne],""),FILTER(Table,Table[Index]=1))
Datediff2 = IF(Table[DateMoyenne]<=Table[first row],DATEDIFF(Table[DateMoyenne],Table[first row],DAY)*(-1),DATEDIFF(Table[first row],Table[DateMoyenne],DAY))

2.JPG

Regards,
Lydia

Hi v-yuezhe-msft,

 

The problem is that the image I show you is not a table

Anonymous
Not applicable

@AlexGallet01,

Where do you store the sample data  you post? Do you want to calculate date difference in Power BI Desktop?

Regards,
Lydia

The data that I have published are measurements and yes it is on power bi desktop

Anonymous
Not applicable

@AlexGallet01,

You may need to create a calculated table containing ValeusrUtilise, DateMoyenne and other fields, then create calculted column using the DAX I provide. 

If you have any questions about creating calculated table, please share raw data of your table and post the DAX you use to create the above measures.

Regards,
Lydia

Hello,

 

As far as values ​​are concerned, they are the values ​​of a column of my table but for the date it is a measure.

 

DateMoyenne = FORMAT(average(TECHNIKE[TEST NON VIDE]);"YYYY-MM-DD")

 

 

Anonymous
Not applicable

@AlexGallet01,


Please help to post sample data of the TECHNIKE table.

Regards,
Lydia Zhang

Sans titre.png

Anonymous
Not applicable

@AlexGallet01,

I haven't seen the TEST NON VIDE column from the table you post. Could you please post complete columns with sample data that can be copied and pasted so  that I can test?

Regards,
Lydia

Hello,

 

I'm again blocked have you got a solution please ?

Anonymous
Not applicable

@AlexGallet01,

Regarding to your last screenshot, do you raise a new requirement? Could you please explain your expected result? For the last  screenshot, do you want to get difference of dates between each row?

And could you please share your PBIX file to me so that I can provide you appropriate DAX? You can upload PBIX file to OneDrive and send me the shared link via Private Message. 

Regards,
Lydia

Hello,

 

If it's possible i want to do a date diff between all date by lign on my new board. And for my project.pbix, i can't to send this because he have a confidential data.

 

Reguards.

Anonymous
Not applicable

@AlexGallet01,

You can share dummy data of your table, and put the data in Excel file, then upload the Excel file to OneDrive and post shared link of the Excel file here.

Regards,
Lydia

Hello,

 

If it's possible i want to do a date diff between all date by lign on my new board. And for my project.pbix, i can't to send this because he have a confidential data.

 

Reguards.

Sans titre.png

Sans titre.png

 

And with this table it's possible to do a datediff between all date of the month ???

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.