Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Date Functions- in measures

Hello,    I have created some measures to look at the count of deliveries in the last 3 months/last 6 months / last 12 months. So if a delivery is from 2 months ago, it will be included in all thr...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous ,

    Please try to update the formula of measure [] and check whether you can get the desired result:

    DeliveryItems_Last 03-06 Months =
    VAR datestart =
        CALCULATE (
            DATEADD ( 'Calendar'[Date], -3MONTH ),
            ALL ( 'Calendar' ),
            'Calendar'[Is Current Day] = TRUE ()
        )
    VAR datesend =
        CALCULATE (
            DATEADD ( 'Calendar'[Date], -6MONTH ),
            ALL ( 'Calendar' ),
            'Calendar'[Is Current Day] = TRUE ()
        )
    RETURN
        CALCULATE (
            COUNT ( 'Transportation Cost'[MaterialKey] ),
            Material[Material Group HL] = "Laminate"
                || Material[Material Group HL] = "Vinyl"
                || Material[Material Group HL] = "Wood",
            FILTER (
                ALL ( 'Calendar' ),
                'Calendar'[Date] >= datestart
                    && 'Calendar'[Date] <= datesend
            ),
            'Customer Sales'[Customer Group] <> "99"
                && 'Customer Sales'[Customer Group] <> "90"
                && 'Customer Sales'[Customer Group] <> "91"
        )

    If the above one is not working in your scenario, please provide some sample data(exclude sensitive data) and your expected result with examples. By the way, what's the data type of field  'Calendar'[Date short]? Its data type is Date or some else type? Thank you.

    Best Regards