Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Summarize Average Date by Batch Number and Movement Type

I would like to summarize the batch numbers by movement type.  For example, Batch 3T36 has multiple entries.  They all have the same movement type but different dates.   I would like to take the aver...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Anonymous ,

    Based on the information, try using the following DAX formula to calculate the date.

    Measure1 = 
    VAR FirstPosting =
        CALCULATE(
            FIRSTDATE(TEST[Posting Date]),
            TEST[Movement Type] = "901",
            TEST[Plant] = "FRPB"
        )
    VAR LastPosting =
        CALCULATE(
            LASTDATE(TEST[Posting Date]),
            TEST[Movement Type] = "901",
            TEST[Plant] = "FRPB"
        )
    VAR MidPosting =
        FirstPosting
            + INT(DATEDIFF( FirstPosting, LastPosting, DAY ) / 2)
    RETURN
        MidPosting
    Measure2 = 
    VAR FirstPosting =
        CALCULATE(
            FIRSTDATE(TEST[Posting Date]),
            TEST[Movement Type] = "68C",
            TEST[Plant] = "FRAA"
        )
    VAR LastPosting =
        CALCULATE(
            LASTDATE(TEST[Posting Date]),
            TEST[Movement Type] = "68C",
            TEST[Plant] = "FRAA"
        )
    VAR _date =
        FirstPosting
            + INT(DATEDIFF( FirstPosting, LastPosting, DAY ) / 2)
    RETURN
        _date
    Measure days = DATEDIFF([Measure1], [Measure2], DAY)

    Then, drag the measure to the card visual.

    Best Regards,

    Wisdom Wu

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