Forum Discussion

Twister8's avatar
Twister8
Icon for Helper II rankHelper II
9 years ago
Solved

sum values with the last date (month)

hello everyone,

 

I am new in PB and DAX, I need calculate the sum of values from the last month with data on my database, for example:

 

month      values

2016-1     1

2016-2     5

2016-3     10

2016-3     10

 

So I need return the 20 in my result.

  • HI,

     

    Tks everybody for answers...

     

    I solved:

    LastMonth = IF(YEAR(TODAY())= YEAR('Fact'[Date]) && MONTH(TODAY())-1 = MONTH('Fact'[Date]);1;BLANK())

     

    Mymeasure = CALCULATE(SUM('Fact'[Value]);'Fact'[LatMonth] =1)

19 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    I created a column like this:

     

    Column = CONCATENATE(YEAR([month]),MONTH([month]))

    switched this to a Whole Number format

     

    and then a measure like this:

     

    SumLatest = SUMX(FILTER(LastMonth,[Column]=MAX([Column])),[values])

     

    • Twister8's avatar
      Twister8
      Icon for Helper II rankHelper II

      Greg_Deckler

      Tks for answer :), but isnt working for me :(

      What is LastMonth? function? When I type Colum = MAX[Column] I have error because Column isnt the Date column

       

       

      I am try use: 

      LastMonth= CALCULATE(SUM('MYtable'[Colum With Value]); PREVIOUSMONTH('MYTableTIME'[Date]))

       

      However when I typed in my expression i can't see the result, because i dont have a total

       

      When I use this:

      LastMonth = CALCULATE([Colum With Value];DATEADD(MYTable[Date]; -1; MONTH))

      the total is all months of all years, i need just last month, in my example month 03, its possible filter the actual year?

  • Hi Twister8

    You can use the CALCULATE function with the LASTNONBLANK function as its filter argument, you will get a result of 20.

     

    Measure = CALCULATE(SUM(Table1[value]),LASTNONBLANK(Table1[date],1))

     

     

    Let me know if it works out.

    Simon