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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
Anonymous
Not applicable

DateDiff until end of month

Hi guys, 

I'm working on a table with several columns: date, product and status. Each product can have several statuses (working, not working). I'm looking to calculate how long each product stayed in a certain status. For this I have a measure that calculates for each product How long has it been until the next time it changes status and so on.

BUT I have a problem the result obtained does not reflect reality. 

if for example a product A was "working" from 01/01/2021 until 01/05/2021 (4 days difference) in this date it will "Not working". 
but the 02/05/2021 it will be "working" so my measure says me that passed from here 30 days. But actually that is not true. Because if I want to display for the January month how many days was the product "not working" so I'll get the result 30 ! But the reality is that in January the product was 25 days in this status and not 30, the five days have to be in the next month ! 

Actually dax have to understand that he have to stop the sum of days at the end of month if not I'lol get fake data with slicers. 
do you have a solution ? 

12 REPLIES 12
tamerj1
Super User
Super User

Hi @Anonymous 

what is the dax of this measure?

Anonymous
Not applicable

In other words ? I didn't understand 

@Anonymous 

"For this I have a measure that calculates for each product How long has it been until the next time it changes status and so on."

What DAX formula have you used for this measure?

Anonymous
Not applicable

This is my measure : 

lastchange= 

var currentproduct = table[product]
var currdate = table[date]
var maxdate = 

MINX(FILTER(Table,Table[Date]>currdate && Table[product]=currentproduct), table[date]) 

RETURN 

(DATEDIFF(currdate,maxdate,SECOND)/3600)

@Anonymous 
Seems to me this is a calculated column rather than a measure?

Anonymous
Not applicable

Yes you right 

but even if it was a measure it not get in count the end of the month and continue to display cumulated values

@Anonymous 
If you have a sample file please share it's download link.

Anonymous
Not applicable

 

I can't because this is confidential data...

but 

this is like this (I filtered just to see one product) the result in hours. 

For example in line 9, the product was in status and line 10 an other status. But meantime this is a new month and if want to display data for December month, it said that there are 264hours between the 27/12/2017 and 07/01/2018. But this is not true because part of the hours in January and not December. 

Hi @Anonymous 
Never asked to share your data. Of course it is confidential. But you can allways create a sample PBIX that contains a data model that simulates your data. Inside import sample data of all invloved tables create the relationships and and create the visual that you are looking for without the required measure(s). This will save for both of us alot of time. Thank you.

Anonymous
Not applicable

Infortunnaly I can't but i don't think we need this to write a Dax measure 

Anonymous
Not applicable

I think your table, you can add a calculated column, eomonth(date) and it should gove you the end of month of every respective row date, 

Anonymous
Not applicable

Ok but what can I do with it after ? 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.