Forum Discussion

AllanBerces's avatar
AllanBerces
Icon for Post Prodigy rankPost Prodigy
1 year ago
Solved

Difference value from previous day to recent date

Hi can anyone help me on how can i calcuate the difference of change between previous date to recent date. The Max Progress date hours minus recent date hours. RESULT Thank you
  • danextian's avatar
    1 year ago

    Try the following  calculated column

    Revision Hours = 
    VAR _job = 'Table'[Job]
    VAR _tbl = 'Table'
    
    -- Latest 2 dates across all jobs
    VAR _latest2 =
        TOPN (
            2,
            VALUES ( 'Table'[Progress Date] ),
            'Table'[Progress Date], DESC
        )
    
    -- Latest 2 dates for this specific job
    VAR _latest2_job =
        TOPN (
            2,
            DISTINCT (
                SELECTCOLUMNS (
                    FILTER ( 'Table', 'Table'[Job] = _job ),
                    "Progress Date", 'Table'[Progress Date]
                )
            ),
            [Progress Date], DESC
        )
    
    -- Global latest & previous
    VAR _latestDate = MAXX ( _latest2, [Progress Date] )
    
    -- Job-specific latest & previous
    VAR _maxJobDate  = MAXX ( _latest2_job, [Progress Date] )
    VAR _prevJobDate = MINX ( _latest2_job, [Progress Date] )
    
    -- Hours for the latest date (job-scoped)
    VAR _latestDateValue =
        MAXX (
            FILTER ( _tbl, [Progress Date] = _maxJobDate && [Job] = _job ),
            [Hours]
        )
    
    -- Hours for the previous date (job-scoped)
    VAR _prevDateValue =
        MAXX (
            FILTER ( _tbl, [Progress Date] = _prevJobDate && [Job] = _job ),
            [Hours]
        )
    
    -- Difference
    VAR _diff = _latestDateValue - _prevDateValue
    
    -- Final result
    VAR _result =
        SWITCH (
            TRUE(),
            'Table'[Progress Date] = _latestDate, _diff,
            'Table'[Progress Date] = _maxJobDate, 0
        )
    RETURN
        _result
    

     

     

  • v-pnaroju-msft's avatar
    1 year ago

    Thankyou, Shahid12523OktayPamuk80rohit1991Kedar_Pande, and danextian for your responses.

    Hi AllanBerces,

    We appreciate your enquiry via the Microsoft Fabric Community Forum.

    Based on my understanding of the scenario, please find attached a screenshot and a sample PBIX file which may help to resolve the issue:


    We hope the information provided assists in resolving the problem. Should you have any further queries, please feel free to contact the Microsoft Fabric Community.

    Thank you.