Forum Discussion

eryka_90's avatar
eryka_90
Helper I
1 year ago
Solved

Cumulative Value based on condition

Hi All,   I want to have cumulative value in my matrix table based on certain condition. Jan 2024 : Posting date < Feb 1st 2024 and clearing date > Jan 31st   Feb 2024 : Posting date < Mac 1st 20...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi, eryka_90 

    You can try the following dax to achieve your need.

     

    Measure:

     

    Net Due = 
    VAR _netDue =
        CALCULATE (
            COUNTROWS ( 'Table' ),
            FILTER (
                'Table',
                MONTH ( 'Table'[Net Due Date] ) - 1
                    = MONTH ( SELECTEDVALUE ( 'Date'[firstDayofMonth] ) )
            )
        )
    RETURN
        _netDue
    
    0-15 = 
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[DaysDiff_1] <= 15
                && MONTH ( 'Table'[Net Due Date] )
                    = MONTH ( SELECTEDVALUE ( 'Date'[firstDayofMonth] ) )
        )
    )
    
    16-31 = 
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            'Table'[DaysDiff_1] < 31
                && 'Table'[DaysDiff_1] > 16
                && MONTH ( 'Table'[Net Due Date] )
                    = MONTH ( SELECTEDVALUE ( 'Date'[firstDayofMonth] ) )
        )
    )
    
    DaysDiff_1 = 
    VAR _netDueDate =
        SELECTEDVALUE ( 'Table'[Net Due Date] )
    VAR _lastDayofMonth =
        EOMONTH ( _netDueDate, 0 )
    VAR _dayDiff =
        INT ( _lastDayofMonth - _netDueDate )
    RETURN
        _dayDiff
    
    DaysDiff_2 = 
    VAR _netDueDate =
        SELECTEDVALUE ( 'Table'[Net Due Date] )
    VAR _lastDayofMonth =
        EOMONTH ( _netDueDate, 1 )
    VAR _dayDiff =
        INT ( _lastDayofMonth - _netDueDate )
    RETURN
        _dayDiff
    

     

     

    Best Regards,
    Yang

    Community Support Team

    If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know.
    Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum