Forum Discussion

ArchStanton's avatar
ArchStanton
Icon for Power Participant rankPower Participant
23 days ago
Solved

Previous Month Measures

I have attached a dummy pbix file that loosely resembles a part of my data model in terms of the kinds of visuals I use and measures required.

As you can see, I need to add a FY filter in the Filter Pane for both column charts, that way I can manually save and lock down a version at close of business 31st Mar each year, then copy and open a new one for 1st Apr where I amend the FY filter.

An issue that I have always struggled with are the 2 Previous Month cards I have highlighted with Red Borders, can someone help me get the previous month's figure? I have tried so many different measures and I can never get the number I want.

This would allow me to use conditional formatting to indicate Up / Down trend on Current vs Previous mth etc.

Any help will be gratefully received.

https://www.dropbox.com/scl/fi/umkrnfgjofj748pjpvwyc/Test.pbix?rlkey=5cso1917a69pnlfof6k9mdclu&st=wrcxmz9d&dl=0

  • aswathimohan's avatar
    aswathimohan
    23 days ago

    Also in this file :

    https://drive.google.com/file/d/1kHn7r4hPx7XF2nFzFi8eEObhJjWVnRxV/view?usp=sharing

    I have tried a similar method of construction of the measures in the page Alternate Methods, somehow it gives a better performance than the measures I have told earlier while using Performance Analyzer.

18 Replies

  • Hi,

    I am assuming that as of today August 2026, you want the "New Previous Month" to be 699 and the "Closed Previous Month" to be 822.

    So I have tried the following measures 

    New Previous Month 2 = VAR _PreviousDate = EOMONTH(TODAY(),-1) VAR _Month_Year = FORMAT(_PreviousDate,"MMMM YYYY") RETURN COUNTROWS( FILTER( Data, FORMAT(Data[Created On],"MMMM YYYY") = _Month_Year ) )
    Closed Previous Month 2 = VAR _PreviousDate = EOMONTH(TODAY(),-1) VAR _Month_Year = FORMAT(_PreviousDate,"MMMM YYYY") RETURN COUNTROWS( FILTER( Data, FORMAT(Data[Resolution Date],"MMMM YYYY") = _Month_Year ) )

    I have done a similar calculation for the current month values but havent changed anything which you have written, just done for clarity purposes.

    https://drive.google.com/file/d/1SkpZ36GatgPxk3ykJlSvj1MRPnIVPpo6/view?usp=sharing

    Ignore the two extra columns created in the fact table as it was done for clarity purposes. Also this might not work if the Status is Resolved and and Resolution date value in the data table is empty

    • aswathimohan's avatar
      aswathimohan
      Icon for Advocate I rankAdvocate I

      Also in this file :

      https://drive.google.com/file/d/1kHn7r4hPx7XF2nFzFi8eEObhJjWVnRxV/view?usp=sharing

      I have tried a similar method of construction of the measures in the page Alternate Methods, somehow it gives a better performance than the measures I have told earlier while using Performance Analyzer.

  •  Here is another option that you can use, create a new column in your Data table that generates an offset date for each month.   (Intially was going to mention to put it in the Calendar table but because this is not an active relationship you have to added in the data table).
    Offset month:

    Month Offset =  VAR CurrentYear = YEAR(TODAY()) VAR CurrentMonth = MONTH(TODAY()) VAR RowYear = YEAR('Data'[Resolution Date]) VAR RowMonth = MONTH('Data'[Resolution Date]) RETURN     (RowYear - CurrentYear) * 12 + (RowMonth - CurrentMonth)

    Create a measure for the Current Month, Previous Month etc.. by changing the offset date only.

    Current Month = -- Create a new measure for each month you need by just changing the offset month number CALCULATE(     COUNT(Data[Case Number]),     'Calendar'[Month Offset]=-0, -- 0 Current month -1 previous month etc..         USERELATIONSHIP(Data[Resolution Date],'Calendar'[Date]))

     

  • Hi

    Previous Month =
    CALCULATE(
    [Your Current Measure],
    PREVIOUSMONTH('Calendar'[Date])
    )

    Make sure 'Calendar' is marked as a Date table and has an active relationship to your fact table. If your card is using a slicer or FY filter, PREVIOUSMONTH needs a continuous date context, not just a single selected month, otherwise it returns blank.

    If it's still off, try DATEADD instead:

    Previous Month = CALCULATE([Your Current Measure], DATEADD('Calendar'[Date], -1, MONTH))

    If this helped, feel free to give it a kudos or mark it as solution, helps others find it too.

    • ArchStanton's avatar
      ArchStanton
      Icon for Power Participant rankPower Participant

      Please look at my pbix file - I've already tried those options!

      • Prince0011's avatar
        Prince0011
        Icon for Solution Sage rankSolution Sage

        I am not able to see and download your file from dropbox try to upload here

  • You can move the logic defining start and end dates and retrieving the relevant dates into a function for ease of reuse, and then you can use that function in both the this month and previous month measures.

    DEFINE  FUNCTION Local.GetThisMonthDates = () =>   VAR StartDate =   IF(    DAY(TODAY()) = 1,    EOMONTH(     TODAY(),     -2    ) + 1,    -- If today is the 1st, use the first day of the previous month    EOMONTH(     TODAY(),     -1    ) + 1 -- Otherwise, use the first day of the current month   )   VAR EndDate =   IF(    DAY(TODAY()) = 1,    EOMONTH(     TODAY(),     -1    ),    -- If today is the 1st, use the last day of the previous month    TODAY() -- Otherwise, use today   )   VAR DatesToUse =   DATESBETWEEN(    Calendar[Date],    StartDate,    EndDate   )   RETURN    DatesToUse   MEASURE 'Measures Table'[New Cases this Month] =   CALCULATE(    COUNTROWS('Data'),    LOCAL.GETTHISMONTHDATES()   )  MEASURE 'Measures Table'[New Previous Month] = CALCULATE(    [New Cases this Month],    DATEADD(     LOCAL.GETTHISMONTHDATES(),     -1,     MONTH    ),    'Data'[status] = "Active"   ) 

    I changed from a COUNT to COUNTROWS as that is a bit more efficient.

    • ArchStanton's avatar
      ArchStanton
      Icon for Power Participant rankPower Participant

      Hi, thanks for replying, I've never written a function before so this is new to me.

      My main issue is to get those 2 Card visuals to show the previous months number - can you see where I'm going wrong?

      The start & end date function is beyond my understanding I'm afraid, Is there any chance you could edit the pbix file with your solution?

      No rush if you can!

  • Hi,

    What is the problem in that file?  In the first card visual, is the answer 180 wrong?  In the second card visual, since you are calculating a YTD figure, there is no concept of a previous month.

    • ArchStanton's avatar
      ArchStanton
      Icon for Power Participant rankPower Participant

      Yes, the previous month should be 909 for Jul and not 180, thats what I am seeking help about.
      The same problem exists for the other card

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Icon for Super User rankSuper User

        Hi,

        The previous month i.e. July 2026 should be 212.  Apply a filter on Active and July 2026 to check please.  This measure returns 212

        New Previous Month =  CALCULATE(     COUNT ( 'Data'[Case Number] ),     DATESBETWEEN('Calendar'[Date],EOMONTH(today(),-2)+1,EOMONTH(today(),-1)),     'Data'[status] = "Active")

        Hope this helps.

         

  • Hi ArchStanton​ 

    I'm confused why, in your example, you use TOTALMTD but still show the monthly value instead of running FYTD value for the month. Also, if you intend to show the running amount, apply the FUNCTION 'Calendar'[Date] and not to Data[Date]. There are also future dates in your calendar table and without specifying a date or period, previous month will be based on the max date in that table. Add a column that indicates whether a date is on or before today and use that as a filter.

    On or Before Today =  'Calendar'[Date] <= TODAY()
    Closed Previous Month =  CALCULATE (     COUNT ( 'Data'[Case Number] ),     'Data'[Status] = "Resolved",     USERELATIONSHIP ( 'Calendar'[Date], 'Data'[Resolution Date] ),     FILTER (         ALL ( 'Calendar' ),         FORMAT ( 'Calendar'[Dates], "YYYY-MM" )             = FORMAT ( EOMONTH ( MAX ( 'Calendar'[Dates] ), -1 ), "YYYY-MM" )     ) ) 

     

    • ArchStanton's avatar
      ArchStanton
      Icon for Power Participant rankPower Participant

      I have tried so many variations of measures that I am not sure what the best way forward is anymore. As I explained to John75, I'm not familiar with the functions and don't really understand what to do.
      My Calendar shows all the dates for FY2026/27, its used for charts where I make projections that are based on current numbers.

      Are you able to update my test file so the 2 cards show the correct previous month figure?

    • ArchStanton's avatar
      ArchStanton
      Icon for Power Participant rankPower Participant

       

      aswathimohan

      has provide me a solution - its not the same as your function solution but it works.
      It would be good to see the function solution in practice if you have time?

  • v-csrikanth's avatar
    v-csrikanth
    Icon for Community Support rankCommunity Support

    Hi ArchStanton​ 

    We would like to inquire whether have you got the chance to check the solutions provided by other users in community to resolve the issue. We hope the information provided helps to clear the query. Should you have any further queries, kindly feel free to contact the Microsoft Fabric community.