Forum Discussion

TonyGu's avatar
TonyGu
Helper I
4 years ago
Solved

DAX Measure needs Help

I am trying to writing a measure that return the count of active patient of the previous month. I have written a measure that return the count of previous year working. But when I expand to month level, it is not working. Here is my Measure:

 

Active Patient Base = 
CALCULATE([Active Base count],
DATESBETWEEN(
DimDates[Date], MAX(DimDates[Date])-365 , MAX(DimDates[Date])))
 
Active Patient Base PY =
CALCULATE([Active Base count],
DATESBETWEEN(
DimDates[Date], MAX(DimDates[Date])-730 , MAX(DimDates[Date])-365))
 

I don't know how to write the DAX measure that return the previous month, since some months are 31 days and some are 30 days.

As shown in the figure below, Oct 2002 should return 31, Nov 2022 should return 92.

 

 

\

 
  • Whitewater100's avatar
    Whitewater100
    4 years ago

    Sorry:

    Active Base Count PM = CALCULATE([Active Base count]PREVIOUSMONTH(DimDates[Date]))

5 Replies

    • TonyGu's avatar
      TonyGu
      Helper I

      I tried this measure but it's not giving what I want.

       

      Active Patient Base PM =
      CALCULATE([Active Base count],
      DATESINPERIOD(
      DimDates[Date],
      MAX(DimDates[Date])-31,
      -1,MONTH)
      )
       

       

       
       
      • CNENFRNL's avatar
        CNENFRNL
        Community Champion

        Not surprising at all that you can't get the right answer. You should learn DAX from scratch, the very first thing is that DAX is NOT Excel worksheet formula; DAX formula is very sensetive to the context where it evaluates. Thus, any discussion over DAX without dataset model is nothing but gibberish.

  • Hello:

     

    COGC PM = CALCULATE([Active Base count], PREVIOUSMONTH(Dates[Date]))
     
    Thanks..
    • Whitewater100's avatar
      Whitewater100
      Solution Sage

      Sorry:

      Active Base Count PM = CALCULATE([Active Base count]PREVIOUSMONTH(DimDates[Date]))