Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TonyGu
Helper I
Helper I

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))
 
TonyGu_0-1645119083871.png

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.

 

TonyGu_1-1645119377902.png

 

\

 
1 ACCEPTED SOLUTION

Sorry:

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

View solution in original post

5 REPLIES 5
Whitewater100
Solution Sage
Solution Sage

Hello:

 

COGC PM = CALCULATE([Active Base count], PREVIOUSMONTH(Dates[Date]))
 
Thanks..

Sorry:

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

CNENFRNL
Community Champion
Community Champion

DATESINPERIOD() comes into play.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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)
)
 
TonyGu_0-1645122027835.png

 

 
 
CNENFRNL
Community Champion
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.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors