Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Value for latest date, changing in time

Hi, I have a problem with creating correct DAX formula that will sum [value] for latest [date], for each [id]. BUT I also have a classic date table, and want to show the sum related to different dat...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous 

    Please try the following Dax:


    Measure = 
    VAR _calendar_month = MONTH(SELECTEDVALUE(tblCalendar[FormattedDate]))
    
    RETURN
    SUMX(FILTER('tblStatus',MONTH('tblStatus'[FormattedDate])=_calendar_month),'tblStatus'[value])


    Then click "Show items with no data":




    Result:

     

     

    Sample pbix file attached.

     

     

     

     

     

    Best Regards,

    Jayleny

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     


     

  • mark_endicott's avatar
    mark_endicott
    2 years ago

    Anonymous - this was not made clear in your requirements. This will populate the prevoius months value where there is not a value for an id.

     

    VAR _end_month =
        MAX ( 'tblCalendar'[date] )
    VAR _start_month =
        EOMONTH ( _end_month, -1 ) + 1
    VAR _val =
        SUMX (
            FILTER (
                'tblStatus',
                'tblStatus'[date] >= _start_month
                    && 'tblStatus'[date] <= _end_month
            ),
            'tblStatus'[value]
        )
    VAR _prev_month_end =
        EOMONTH ( _end_month, -1 )
    VAR _prev_month_start =
        EOMONTH ( _end_month, -2 ) + 1
    VAR _Prev_val =
        SUMX (
            FILTER (
                'tblStatus',
                'tblStatus'[date] >= _prev_month_start
                    && 'tblStatus'[date] <= _prev_month_end
            ),
            'tblStatus'[value]
        )
    RETURN
        IF ( NOT ISBLANK ( _val ), _val, _Prev_val )

     

    If this works for you, please accept it as the solution, it helps with visibility for others with the same issue.