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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
amikm
Helper V
Helper V

Issue with Date during closed year

I have a table that has all the dates from 01/01/2020 to  31/12/2020

I am writing a DAX measure to calculate Sales based on dates
Sales=CALCULATE(SUM(Sales[Sale]),
FILTER(Sales,Sales[CYPY]="CY"))

 

CYPY=IF(YEAR(Date[Date])=YEAR(TODAY())-1,"PY",
IF(YEAR(Date[Date])=YEAR(TODAY()),"CY","Others"))

 

Here I am getting Sales value as blank, ideally, the value should show for sales as Jan 2021 is not completed as per business and it shows to compare the year of Dec 2020 and Dec 2020 should be my current Year "CY".

 

I want to show Dec 2020 as CY as I will be running the report in Jan 2021 and Jan 2021 is not yet completed so Dec 2020 will be my CY but when I will be in Feb 2021 and Feb 2021 is not completed and I am running my report, in that case, Jan 2021 will act as CY.

 

I am not able to handle year-end issues

 

6 REPLIES 6
Anonymous
Not applicable

Hi @amikm ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business after removing sensitive data.

 

Best Regards,
Eyelyn Qin

Anonymous
Not applicable

Hi @amikm ,

 

You could use the following formula to modify the CYPY logic:

 

CYPY =
IF (
    MONTH ( TODAY () ) > 1,
    IF ( YEAR ( [Date] ) = YEAR ( TODAY () ) - 1, "PY", "CY" ),
    IF (
        YEAR ( [Date].[Date] )
            = YEAR ( TODAY () ) - 1
            && MONTH ( [Date] ) = 12
            || YEAR ( [Date] ) = YEAR ( TODAY () ),
        "CY",
        "PY"
    )
)

 

 

Here is the pbix file.

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

parry2k
Super User
Super User

@amikm I have a post which talks about delayed month end, you can take the similar approach delayed year-end or you can build the logic for CY that in Feb it take the current year as CY otherwise it should take the previous year as CY.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@amikm first and foremost, anytime you want to work with dates, you must add a date dimension into your model. This is important and must be part of your model. There are many posts on how you can add one but here is one of my posts.

 

Once the date dimension is added, you can have this CY and PY column in your date dimension and then write the following measure

 

Sales=
CALCULATE(
SUM(Sales[Sale]),
Date[CYPY]="CY")
)

 

Follow best practices, it will save your time and help to develop a scalable solution.

 

Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @parry2k ,

 

Yeah, actually the challenge is with CYPY logic, where, I want to display Dec 2020 as current year as per business logic, I am using YEAR(TODAY()) and it is giving me 2021, that might be true If I will be running my report in mid of Feb 2021, in that case, Jan 2021 data should show.

 

But when I am running my report in mid of Jan 2021 I want to show Dec 2020 data (as jan 21) is not completed.

I am not able to handle year-end situations, 

When I am running my report in Jan 2021

Month, Year, CYPY

Dec 2020 CY
Jan 2021 CY

 

When I will run my report in Feb 2021

Month, Year, CYPY

Dec 2020 PY
Jan 2021 CY

FEB 2021 CY

 

Note: report where displaying correct data during Jan 20 -Dec 20, but it starts failing in the month of Jan 21

 

Pragati11
Super User
Super User

Hi @amikm ,

 

Can you attach a small sample data file, so that I can try this at my end?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors