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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
tuncay
Helper III
Helper III

How to build YTD value based on the filtered month

Hello community,

 

I try to build YTD based on the selected month.

For example:

February is selected → YTDvalue = (SUM(OEE) where MonthNo is 1 and 2)/2

 

see example:

 

OEE_ACT_YTD = 
var plant = SELECTEDVALUE('DPC Raw Data query for Power BI'[Org. Unit.Level 04])
var getmonth = SELECTEDVALUE('DPC Raw Data query for Power BI' [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo])
var z = CALCULATE(AVERAGE('DPC Raw Data query for Power BI'[OEE - Overall Equipment Effectiveness [%]]]), FILTER( ALL('DPC Raw Data query for Power BI'), 
[Version.Version Level 01.Key] = "103" &&
[Calendar Year/Month.Calendar Year/Month Level 01].[Jahr] = YEAR(TODAY()) &&
[Org. Unit.Level 04] = plant))
return z

 

But it always considers all months. When I select January it does not consider only Januar it considers all months and makes the average of all..

 

1 ACCEPTED SOLUTION

OEE_ACT_YTD = 
var plant = SELECTEDVALUE('DPC Raw Data query for Power BI'[Org. Unit.Level 04])
var getmonth = SELECTEDVALUE('DPC Raw Data query for Power BI' [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo])
var z = CALCULATE(AVERAGE('DPC Raw Data query for Power BI'[OEE - Overall Equipment Effectiveness [%]]]), FILTER( ALL('DPC Raw Data query for Power BI'), 
[Version.Version Level 01.Key] = "103" &&
[Calendar Year/Month.Calendar Year/Month Level 01].[Jahr] = YEAR(TODAY()) &&
[Org. Unit.Level 04] = plant && [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo] <= getmonth))
return z

 

I forget to change it in the measure, now it would work

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with and show the expected result.


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

Hello @tuncay ,

 

it looks like you miss to add getmonth in your filter.

 

Would be like this :

 

OEE_ACT_YTD = 
var plant = SELECTEDVALUE('DPC Raw Data query for Power BI'[Org. Unit.Level 04])
var getmonth = SELECTEDVALUE('DPC Raw Data query for Power BI' [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo])
var z = CALCULATE(AVERAGE('DPC Raw Data query for Power BI'[OEE - Overall Equipment Effectiveness [%]]]), FILTER( ALL('DPC Raw Data query for Power BI'), 
[Version.Version Level 01.Key] = "103" &&
[Calendar Year/Month.Calendar Year/Month Level 01].[Jahr] = YEAR(TODAY()) &&
[Org. Unit.Level 04] = plant && [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo] = getmonth))
return z

 Have a nice day

but then it only considers the selected month, e. g. when February is selected it only Sums FEB data but it should sum JAN AND FEB

@tuncay , juste replace = with <=

 

Like this :

OEE_ACT_YTD = 
var plant = SELECTEDVALUE('DPC Raw Data query for Power BI'[Org. Unit.Level 04])
var getmonth = SELECTEDVALUE('DPC Raw Data query for Power BI' [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo])
var z = CALCULATE(AVERAGE('DPC Raw Data query for Power BI'[OEE - Overall Equipment Effectiveness [%]]]), FILTER( ALL('DPC Raw Data query for Power BI'), 
[Version.Version Level 01.Key] = "103" &&
[Calendar Year/Month.Calendar Year/Month Level 01].[Jahr] = YEAR(TODAY()) &&
[Org. Unit.Level 04] = plant && [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo] = getmonth))
return z

 

Have a nice day

tried, does not work..

OEE_ACT_YTD = 
var plant = SELECTEDVALUE('DPC Raw Data query for Power BI'[Org. Unit.Level 04])
var getmonth = SELECTEDVALUE('DPC Raw Data query for Power BI' [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo])
var z = CALCULATE(AVERAGE('DPC Raw Data query for Power BI'[OEE - Overall Equipment Effectiveness [%]]]), FILTER( ALL('DPC Raw Data query for Power BI'), 
[Version.Version Level 01.Key] = "103" &&
[Calendar Year/Month.Calendar Year/Month Level 01].[Jahr] = YEAR(TODAY()) &&
[Org. Unit.Level 04] = plant && [Calendar Year/Month.Calendar Year/Month Level 01].[MonthNo] <= getmonth))
return z

 

I forget to change it in the measure, now it would work

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors