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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
asteinbach
Frequent Visitor

Dynamic YTD Based On Slicer

Hello,

 

A bit newer to power BI here. I'm trying to create a measure that calculates YTD based on a slicer. I can't attach the dashboard because of privacy issues, but I will do my best to describe the corresponding tables. 

 

I have a table called "Revenue" that has the following columns:

     Year

     Month

     Account

     Scenario

     Value

     Month Number (related function with another table)

 

There is another table called Months that has three columns called month number, month, and date_format (in a proper date format). This table has a relationship with revenue, and drives the related funtion on the other table.

 

There is a slicer on my dashboard for date_format (months). 

 

What I'm trying to do is dynamically calculate a YTD revenue based on the month chosen on the slicer, but I can't do it.  Essentially, when "April" is chosen, it should be the sum of all correponding revenue less than or equal to the month number column on my revenue table, but I can't get it to work properly. This measure will be put onto a matrix and organized by "unit", which is another table with a relationship to revenue. Below is the function I've tried to use, but I can't get it to work properly. 

 

 

 

Rev YTD Test = calculate(sum(Revenue_COGS[Value]),filter(all(Revenue_COGS),Revenue_COGS[Scenario]="ACTUAL" & Revenue_COGS[Year] = "2021" & Revenue_COGS[Account] = "Revenue" & Revenue_COGS[Month Number] <= value(selectedvalue(Months[Date_Format].[Month]))))

 

 

 

If anyone could help me that would be amazing, if need be I can send the pbi file with dummy data. 

 

Thanks in advance. 

1 ACCEPTED SOLUTION

Hi @asteinbach ,

Modify your 2 measures as below:

 

Revenue_Calc_2021_Actual = Calculate(sum('Revenue_COGS'[Value]),'Revenue_COGS'[Account] = "Revenue",'Revenue_COGS'[Year]=2021,'Revenue_COGS'[Scenario] = "ACTUAL",FILTER(Revenue_COGS,DATE('Revenue_COGS'[Year],Revenue_COGS[Month Number],1)<=SELECTEDVALUE('Months'[Date_Format]))

EBITDA_Actual = (Revenue_COGS[Revenue_Calc_2021_Actual] - Calculate(sum(Costs[Value]),Costs[Year]=2021,Costs[Scenario]="ACTUAL",FILTER('Costs',
DATE('Costs'[Year],'Costs'[Month Number],1)<=SELECTEDVALUE('Months'[Date_Format]))) + [Dep_Amo_Impair_Actual])

 

And you will see:

vkellymsft_1-1626946623332.png

As for the orientation from Department_Hiearchy to Revenue_COGS is single and one to many,so when you use month from table Months,the data cant be filtered correctly.That's why you have to add the month filter to the expressions.

Check my .pbix file attached.

 

Best Regards,
Kelly

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

 

 

 

View solution in original post

8 REPLIES 8
v-kelly-msft
Community Support
Community Support

Hi  @asteinbach ,

 

Have you checked my last reply?Is your issue solved now?

 

Best Regards,
Kelly

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

v-kelly-msft
Community Support
Community Support

Hi @asteinbach ,

 

Pls share your pbi file with dummy data.

 

Best Regards,
Kelly

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

 

 

Let me know if this link works. Essentially, the calculation should (theoretically) be a calculate based on the selectedvalue of the slicer. So for "May", it should be the sum of all values equal to or before May in the table. However, I couldn't get that to work.

Hi @asteinbach ,

Modify your 2 measures as below:

 

Revenue_Calc_2021_Actual = Calculate(sum('Revenue_COGS'[Value]),'Revenue_COGS'[Account] = "Revenue",'Revenue_COGS'[Year]=2021,'Revenue_COGS'[Scenario] = "ACTUAL",FILTER(Revenue_COGS,DATE('Revenue_COGS'[Year],Revenue_COGS[Month Number],1)<=SELECTEDVALUE('Months'[Date_Format]))

EBITDA_Actual = (Revenue_COGS[Revenue_Calc_2021_Actual] - Calculate(sum(Costs[Value]),Costs[Year]=2021,Costs[Scenario]="ACTUAL",FILTER('Costs',
DATE('Costs'[Year],'Costs'[Month Number],1)<=SELECTEDVALUE('Months'[Date_Format]))) + [Dep_Amo_Impair_Actual])

 

And you will see:

vkellymsft_1-1626946623332.png

As for the orientation from Department_Hiearchy to Revenue_COGS is single and one to many,so when you use month from table Months,the data cant be filtered correctly.That's why you have to add the month filter to the expressions.

Check my .pbix file attached.

 

Best Regards,
Kelly

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

 

 

 

Hi Kelly,

 

Thank you for sending that over. It seems this still doesn't achieve what I'm hoping to get. Those calculations still yield only monthly results (although with significantly more efficent expressions that the ones I currently have.) From what I can tell, when I change the slicers, those calculations still yield only monthly results. What I'm hoping to get is the results from the calcluations you altered, but the summation of the currently selected month in the slicer, and all prior months before that, if that makes sense. 

 

For example, if May is selected in the slicer, the YTD revenue for Actual (total) should be 146,292,211. If April is selected, the YTD revenue should 82,288,481. The current calculation still spits out 64,003,730 for May and 57,647,527 for April. Those are correct for those specific months, they aren't YTD numbers. I know these from offline calcualtions.

Hi  @asteinbach ,

 

Do you mean the result I marked in red?

vkellymsft_0-1627291549692.png

Best Regards,
Kelly

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

Kelly,

 

I accidentally marked your last post as a solution, but no it still doesn't work. When I change the month slicer, it does in fact change Revenue Actual. This is because it's being displayed by the "Dynamic Revenue" Measure with Revenue YTD, which is an awful IF statement I wrote and the reason I'm trying to get a better way to do it. The formula you edited still doesn't calculate YTD when the slicer is changed, it's still that single month

Greg_Deckler
Super User
Super User

@asteinbach Hard to be specific without sample/example data. 

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors