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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
gennaro_19
Helper I
Helper I

I only want to compare the visible months

hj
My sales database runs from January 2024 to March 2025.
I like to compare the sales of the current year with those of the same period in the previous year.

gennaro_19_1-1742112361360.png

I created my own measure and it works well at month level.

PY Sales = IF(
    ISBLANK(
        MAX('Sales'[Data])), BLANK(),
        CALCULATE(
            [CY Sales],
            SAMEPERIODLASTYEAR('Calendar'[Date])
        )
)

 

 

The measure does not work well at the yearly total level because it gives me the total of all months of the previous year.

Instead, I would like to have, at the total level, only the sum of the visible months, in this case, January to March 2025.

How do I modify my measure?

I enclose the file.
https://drive.google.com/file/d/19e9GHE8j6lzJwsNrbx_Zdj4PpEadoruT/view?usp=drive_link
Thank you

 

1 ACCEPTED SOLUTION

PY Sales =
IF(
   Not ISBLANK(MAX('Sales'[Data])),
   CALCULATE(
      [CY Sales],
      DATEADD(
         DATESBETWEEN( calandar[date], min(calandar[date], max(sales[date]))
      ), -12, month )
   )
)

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Access denied message.  Check the download link.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hj @Ashish_Mathur ,
Thank you for your attention.
I shared the.pbix file on google drive.
I don't know why, but following the link shows a confusing window.
However, if you select the download icon, the next window is the classic file download window.
In the file you will find my old measure that does not work and the new one suggested by Duke that does work.
bye & thks

gennaro_19_1-1742189969191.png

 



Deku
Super User
Super User

Think this should do it. Assumes your calendar table only have dates up to mar 25

 

PY Sales =

IF(
Not ISBLANK(MAX('Sales'[Data])),
CALCULATE(
[CY Sales],
DATEADD(

Values( calendar[date] )

), -12, month )
)
)


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Thank you very much @Deku for your solution, but it requires updating, extending, the calendar table every month when new sales data arrive.
I do not want to update the calendar table every month.
I would like a dynamic solution.
Sorry and thanks

PY Sales =
IF(
   Not ISBLANK(MAX('Sales'[Data])),
   CALCULATE(
      [CY Sales],
      DATEADD(
         DATESBETWEEN( calandar[date], min(calandar[date], max(sales[date]))
      ), -12, month )
   )
)

Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

thank you very much
🙏👍👋

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.