Forum Discussion

dmurali1829's avatar
dmurali1829
Regular Visitor
4 years ago
Solved

Calculate Date diff based on selected category

Hi

 

In the below table i want to calculate date difference keeping one category in Day as 0, in this case Day 0 as 0 and it should considering for substrating other dates eiher + or -, i will be having mutliple ID, can you please help

IDDayDate Diff
1001Day -1515-Aug-21-31
1001Day -1025-Aug-21-21
1001Day 0 15-Sep-210
1001Day 151-Oct-2116
1001Day 2430-Oct-2145
1001End15-Dec-2175
1002Day -1525-Aug-21-21
1002Day -1030-Aug-21-16
1002Day 0 15-Sep-210
1002Day 1525-Oct-2140

Regards

Murali

  • Hi dmurali1829 

     

    You can create a column with below DAX.

    Date Diff = 
    VAR _day0 =
        MAXX (
            FILTER (
                TableName,
                TableName[ID] = EARLIER ( TableName[ID] )
                    && TableName[Day] = "Day 0"
            ),
            TableName[Date]
        )
    RETURN
        DATEDIFF ( _day0, TableName[Date], DAY )
    

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.

2 Replies

  • dmurali1829's avatar
    dmurali1829
    Regular Visitor
    IDDayDate Diff
    1001Day -1515-Aug-21-31
    1001Day -1025-Aug-21-21
    1001Day 0 15-Sep-210
    1001Day 151-Oct-2116
    1001Day 2430-Oct-2145
    1001End15-Dec-2175
    1002Day -1525-Aug-21-21
    1002Day -1030-Aug-21-16
    1002Day 0 15-Sep-210
    1002Day 1525-Oct-2140
  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi dmurali1829 

     

    You can create a column with below DAX.

    Date Diff = 
    VAR _day0 =
        MAXX (
            FILTER (
                TableName,
                TableName[ID] = EARLIER ( TableName[ID] )
                    && TableName[Day] = "Day 0"
            ),
            TableName[Date]
        )
    RETURN
        DATEDIFF ( _day0, TableName[Date], DAY )
    

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.