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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
regnidem16
New Member

Calculating YTD using a month name slicer

I'm not really sure how to best summarize what I'm trying to do.

 

I have a month name slicer.  I'm attempting to create two measures, Prior Year YTD and Current Year YTD., so that when the user selects one of the months in the slicer it calculates the YTD up to that month.  For example, using the data in the table below, if January was selected in the slicer, the result for the previous year should be 244744 and for the current year it would be 23979. If February was select, then for the previous year the result would be 438124 and for the current year it would be 23979. If March was selected, the result for the previous year would be 485285 and for the current year it would be 41150.

 

Invoice DateInvoiceLineAmountSegment
3/29/202447487.49J. GLP Revenue
3/29/20245618.92J. GLP Revenue
3/29/202485135.14J. GLP Revenue
3/29/20249237.16J. GLP Revenue
3/29/20244256.76J. GLP Revenue
3/29/202421719.13J. GLP Revenue
3/29/202426391.89J. GLP Revenue
3/29/202419979.34J. GLP Revenue
3/29/202423160.9J. GLP Revenue
3/29/2024186128.08J. GLP Revenue
3/29/202415421.77J. GLP Revenue
3/29/20249990J. GLP Revenue
3/29/2024275J. GLP Revenue
3/29/2024-198086J. GLP Revenue
3/29/2024-245738J. GLP Revenue
3/29/2024-370.5J. GLP Revenue
3/29/20246564.16J. GLP Revenue
2/28/202363702.18J. GLP Revenue
2/28/202330331.76J. GLP Revenue
1/25/2023228133.4J. GLP Revenue
3/31/202347160.88J. GLP Revenue
2/28/202399346.04J. GLP Revenue
1/31/202316611.42J. GLP Revenue
1/31/202423979.63J. GLP Revenue

 

I tried modifying my YTD measure to achieve this, but have not been successful.  The closest I've gotten (with chatGPTs help) is 

Previous Year YTD =
VAR SelectedMonth = SELECTEDVALUE('Date'[Month Name])
RETURN
CALCULATE(
TOTALYTD(
SUM('Data'[InvoiceLineAmount]),
'Date'[Date]
),
'Date'[Month Name] = SelectedMonth,
ALL('Data'),
SAMEPERIODLASTYEAR('Date'[Date])
)

 

 

however, it's simply returning the same value for each different revenue segment.



Does anyone have any insight on how to acheive my goal?

1 ACCEPTED SOLUTION
xifeng_L
Solution Supplier
Solution Supplier

Hi @regnidem16 ,

 

You need to create a calendar table and establish a one to many relationship with the fact table.

 

Then, use the measures of below:

 

Current Year YTD = CALCULATE(SUM('Fact'[InvoiceLineAmount]),DATESYTD('Calendar'[Date]))

Previous Year YTD = CALCULATE(SUM('Fact'[InvoiceLineAmount]),DATESYTD(SAMEPERIODLASTYEAR('Calendar'[Date])))

 

The result as follow:

 

xifeng_L_0-1715415401881.png

 

For the convenience of displaying the results of different options in the slicer, I have placed the month field in the matrix.

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @regnidem16 ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
xifeng_L
Solution Supplier
Solution Supplier

Hi @regnidem16 ,

 

You need to create a calendar table and establish a one to many relationship with the fact table.

 

Then, use the measures of below:

 

Current Year YTD = CALCULATE(SUM('Fact'[InvoiceLineAmount]),DATESYTD('Calendar'[Date]))

Previous Year YTD = CALCULATE(SUM('Fact'[InvoiceLineAmount]),DATESYTD(SAMEPERIODLASTYEAR('Calendar'[Date])))

 

The result as follow:

 

xifeng_L_0-1715415401881.png

 

For the convenience of displaying the results of different options in the slicer, I have placed the month field in the matrix.

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Kudoed Authors