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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
harshadrokade
Post Partisan
Post Partisan

Days spent in stage

Hi sir/mam,

 

I have below data and I want to generate 'Days spent on the Oldstage' column in power bi. I have also given referance column to know how I calculated this column in excel. Basically I want to know how many days were spent at a stage befor moving to a new stage. I want to follow the sequence of the stages as A>B>C>D.

 

IdMovement start DateOldStageNewStageDays spent on the OldstageFormula for referance
128-10-20 15:32BC7.587199074C date - B date
128-10-20 15:29AB0.001886574B date - A date
105-11-20 5:38CD3D date - C date
108-11-20 5:38DENANA
228-11-20 15:29AB1B date - A date
229-11-20 15:29BC10C date - B date
209-12-20 15:29CD2D date - C date
211-12-20 15:29DENANA
4 REPLIES 4
Fowmy
Super User
Super User

@harshadrokade 

Create the following calculated column in your table:?

Days Spent = 

VAR __FromStage = Stages[OldStage]
VAR __TOStage = Stages[NewStage]
VAR __FromTime = 
    CALCULATE(
        MAX( Stages[Movement start Date] ) , 
        Stages[OldStage] = __TOStage,
        ALLEXCEPT( Stages , Stages[Id] )
    )
VAR __Result= 
         DATEDIFF( Stages[Movement start Date] , __FromTime , DAY ) 
RETURN
    __Result
        

Fowmy_0-1701595238316.png

 





Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

danextian
Super User
Super User

Hi @harshadrokade ,

 

For row 2, 8-10-20 15:29 + 0.001886574 = 28-10-2020 15:31 but this  datetime is not anywhere in your sample data.  And is this by Id?






Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu.

Thanks @danextian for looking into this.

 

I have this datetime, its actually 28-10-20 15:32.Ignore the last decimaldue to rounding off..

 

It is the start day/time of Stage B. When I compare this date with start day/time of Stage A (28-10-20 15:29), I get value as 0.001886574.

 

 

Hi @harshadrokade 

Days spent = 
CALCULATE (
    MAX ( 'Table'[Movement start Date] ),
    FILTER (
       'Table', 
        'Table'[OldStage] = EARLIER ( 'Table'[NewStage] ) && 'Table'[Id] = EARLIER( 'Table'[Id])
    )
) - 'Table'[Movement start Date]





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors