Forum Discussion

pattie_2022's avatar
pattie_2022
New Member
3 years ago
Solved

DATEADD not calculating

I have an imported excel workbook "Inventory Summary" and I also have a Calendar Table. However, I cant get this code to work. Any help would be awesome.

Hardware Inventory Previous Month = CALCULATE(SUM('Inventory Summary xls'[Value] ), FILTER('Inventory Summary xls','Inventory Summary xls'[Description] = "Hardware"),DATEADD('Inventory Summary xls'[Date],-1,MONTH))
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi  pattie_2022 ,

    I created some data:

    Here are the steps you can follow:

    1. Create measure.

    Hardware Inventory Previous Month =
    var _lastmonth=DATE(YEAR(MAX('Inventory Summary xls'[Date])),MONTH(MAX('Inventory Summary xls'[Date]))-1,DAY(MAX('Inventory Summary xls'[Date])))
    return
    SUMX(FILTER(ALL('Inventory Summary xls'),
    'Inventory Summary xls'[Date]>=_lastmonth&&'Inventory Summary xls'[Date]<=MAX('Inventory Summary xls'[Date])&&
    'Inventory Summary xls'[Description]="Hardware"),[Value])

    2. Result:

     

    Best Regards,

    Liu Yang

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

2 Replies

  • Hi,

    Try these measures

    Inventory = SUM('Inventory Summary xls'[Value])

    Hardware inventory = calculate([Inventory],'Inventory Summary xls'[Description] = "Hardware")

    Hardware inventory in PM = calculate([Hardware inventory],previousmonth(calendar[date]))

    Ensure that to your visual/filters/slicer, you drag Year and/or Month name from the Calendar Table.

    Hope this helps.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  pattie_2022 ,

    I created some data:

    Here are the steps you can follow:

    1. Create measure.

    Hardware Inventory Previous Month =
    var _lastmonth=DATE(YEAR(MAX('Inventory Summary xls'[Date])),MONTH(MAX('Inventory Summary xls'[Date]))-1,DAY(MAX('Inventory Summary xls'[Date])))
    return
    SUMX(FILTER(ALL('Inventory Summary xls'),
    'Inventory Summary xls'[Date]>=_lastmonth&&'Inventory Summary xls'[Date]<=MAX('Inventory Summary xls'[Date])&&
    'Inventory Summary xls'[Description]="Hardware"),[Value])

    2. Result:

     

    Best Regards,

    Liu Yang

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