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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.