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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! 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
Deku
Community Champion
Community Champion

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

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

Deku
Community Champion
Community Champion

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
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors