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
ROCKYDO12
Helper III
Helper III

YTD and LYTD calculation Issue

Hello,

 

I am trying to create some KPI's and I am using the following calculations for CYTD Sales and LYTD Sales:

 

CYTD Sales: CALCULATE(SUM('Sales Base'[Amount]),DATESYTD(('Calendar'[Date]),"3/31"))

LYTD Sales:  CALCULATE(SUM('Sales Base'[Amount]),DATESYTD(dateadd('Calendar'[Date],-1,Year),"3/31"))

 

I have added a date calender and have a relationship between my sales table and calender table. I am having an issue as the amounts are showing full year amounts, instead of YTD. Then when I try to use the Sales table dates inplace for calender dates it shows up as blank. 

2 ACCEPTED SOLUTIONS

Hi @ROCKYDO12 ,

 

Your measures should work. There are other peculiarities in your model that could be causing this. Please see this PBIX for you reference - https://drive.google.com/file/d/108pq_k-N8CPQt5hTsaZgU8rP9h4L2dKs/view?usp=sharing 

danextian_0-1655774877673.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

Hi @ROCKYDO12 ,

 

Your measures work fine after creating the relationship which was not in the file you attached.

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

danextian_0-1655855299689.pngdanextian_1-1655855313024.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

21 REPLIES 21
danextian
Super User
Super User

Hi @ROCKYDO12 ,

 

How does the relationship between the two table flow?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

ROCKYDO12_1-1655773461012.png

 

Hi @ROCKYDO12 
I was referring to the cross filter direction. 

danextian_0-1655773754869.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Single, same as yours! Not sure if this could play a factor but my calender table the date has a hierarchy and my sale table the date table does not.

Hi @ROCKYDO12 ,

 

Your measures should work. There are other peculiarities in your model that could be causing this. Please see this PBIX for you reference - https://drive.google.com/file/d/108pq_k-N8CPQt5hTsaZgU8rP9h4L2dKs/view?usp=sharing 

danextian_0-1655774877673.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thank you for this! I am trying to create a YTD slicer that will allow me to flip between full year and YTD. Essentially I am thinking I would have one field for amount and one for Previous year amount using SAMEPERIODLASTYEAR. Then I would need a slicer so i can flip back and fourth. Could you assit with this?

Hi @ROCKYDO12 ,

 

Try the fields parameter feature. Update your version of Power BI Desktop if it isn't available.

https://docs.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

How would this work if I have 9 visuals showing full year amounts for current year and previous year? What fields do I need to use for the parameter? Is there an easier way of just adding a slicer? 

It must be my calender. I need this calender because my FY runs Arpil 1 - March 31st and also I need all the fields for filters and calculations and such. Is there any way I can make calculations work using this calender?

Calendar =
VAR FirstFiscalMonth = 4 -- First month of the fiscal year
VAR FirstDayOfWeek = 0 -- 0 = Sunday, 1 = Monday, ...
VAR FirstSalesDate = MIN ( 'Sales Base'[Sale Date] )
VAR LastSalesDate = MAX ( 'Sale Base'[Sale Date] )
VAR FirstFiscalYear = -- Customizes the first fiscal year to use
YEAR ( FirstSalesDate )
+ 1 * ( MONTH ( FirstSalesDate ) >= FirstFiscalMonth && FirstFiscalMonth > 1)
VAR LastFiscalYear = -- Customizes the last fiscal year to use
YEAR ( LastSalesDate )
+ 1 * ( MONTH ( LastSalesDate ) >= FirstFiscalMonth && FirstFiscalMonth > 1)
RETURN
GENERATE (
VAR FirstDay =
DATE (
FirstFiscalYear - 1 * (FirstFiscalMonth > 1),
FirstFiscalMonth,
1
)

VAR LastDay =
DATE (
LastFiscalYear + 1 * (FirstFiscalMonth = 1),
FirstFiscalMonth, 1
) - 1
RETURN
CALENDAR ( FirstDay, LastDay ),

VAR CurrentDate = [Date]
VAR Yr = YEAR ( CurrentDate ) -- Year Number
VAR Mn = MONTH ( CurrentDate ) -- Month Number (1-12)
VAR Mdn = DAY ( CurrentDate ) -- Day of Month
VAR DateKey = Yr*10000+Mn*100+Mdn
VAR Wd = -- Weekday Number (0 = Sunday, 1 = Monday, ...)
WEEKDAY ( CurrentDate + 7 - FirstDayOfWeek, 1 )
VAR WorkingDay = -- Working Day (1 = working, 0 = non-working)
( WEEKDAY ( CurrentDate, 1 ) IN { 2, 3, 4, 5, 6 } )
VAR Fyr = -- Fiscal Year Number
Yr + 1 * ( FirstFiscalMonth > 1 && Mn >= FirstFiscalMonth )
VAR Fmn = -- Fiscal Month Number (1-12)
Mn - FirstFiscalMonth + 1 + 12 * (Mn < FirstFiscalMonth)
VAR Fqrn = -- Fiscal Quarter (string)
ROUNDUP ( Fmn / 3, 0 )
VAR Fmqn =
MOD ( FMn - 1, 3 ) + 1
VAR Fqr = -- Fiscal Quarter (string)
FORMAT ( Fqrn, "\Q0" )
VAR FirstDayOfYear =
DATE ( Fyr - 1 * (FirstFiscalMonth > 1), FirstFiscalMonth, 1 )
VAR FirstDayFY =
DATE (
Fyr - 1 * (FirstFiscalMonth > 1),
FirstFiscalMonth,
1
)
VAR LastDayFY =
DATE (
Fyr * (FirstFiscalMonth > 1),
FirstFiscalMonth,
1
)
VAR Fydn =
SUMX (
CALENDAR ( FirstDayOfYear, CurrentDate ),
1 * ( MONTH ( [Date] ) <> 2 || DAY ( [Date] ) <> 29 )
)
RETURN ROW (
"DateKey", INT ( DateKey ),
"First Day in FY", FORMAT ( FirstDayFY, "dd mmm yyyy" ),
"Last Day in FY", FORMAT ( LastDayFY, "dd mmm yyyy" ),
"Sequential Day Number", INT ( [Date] ),
"Year Month", FORMAT ( CurrentDate, "mmm yyyy" ),
"Year Month Number", Yr * 12 + Mn - 1,
"Fiscal Year", "FY " & Fyr,
"Fiscal Year Number", Fyr,
"Fiscal Year Quarter", "F" & Fqr & "-" & Fyr,
"Fiscal Year Quarter Number", CONVERT ( Fyr * 4 + FQrn - 1, INTEGER ),
"Fiscal Quarter", "F" & Fqr,
"Month", FORMAT ( CurrentDate, "mmm" ),
"Fiscal Month Number", Fmn,
"Fiscal Month in Quarter Number", Fmqn,
"Day of Week", FORMAT ( CurrentDate, "ddd" ),
"Day of Week Number", Wd,
"Day of Month Number", Mdn,
"Day of Fiscal Year Number", Fydn,
"Working Day", IF ( WorkingDay, "Working Day", "Non-Working Day" )
)
)

Can you share sanitized copy of your pbix? It is easier to figure it out that way.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Please make this available to the public.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Access Denied message.


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

That is a link to a mail attachment. Share using GDrive or OneDrive.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @ROCKYDO12 ,

 

Your measures work fine after creating the relationship which was not in the file you attached.

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

danextian_0-1655855299689.pngdanextian_1-1655855313024.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi,

I get an error when i click on that link.


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

I get this message when i try to open the file.

Untitled.png


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

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.