Forum Discussion

D_PBI's avatar
D_PBI
Icon for Post Partisan rankPost Partisan
3 years ago
Solved

How to count days between two dates grouped by two attributes?

Hi. Please view the below example table, which also includes the desired result to the right. You will notice each ID has mutiple Statuses and each have their own Start Date and End Date. I need to...
  • Nathaniel_C's avatar
    3 years ago

    Hi D_PBI ,

    If I understand your issue, please try this.
    My example:



    Period = 
    
    Var _id = MAX('Status'[ID])
    Var _series = MAX('Status'[Series])
    
    var _MinDate = CALCULATE(min('Status'[Start Date]),FILTER(All('Status'),'Status'[ID]= _id && 'Status'[Series]=_series))
    var _MaxEndDate = CALCULATE(MAX('Status'[End Date]),FILTER(All('Status'),'Status'[ID]= _id && 'Status'[Series]=_series))
    var _dateDif= DATEDIFF(_MinDate,_MaxEndDate,DAY)
    
    Return _dateDif

     


    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
    Nathaniel