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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Calculate the MTD and YTD for the corresponding dax.

I am having a table where there are duplication of column code and its corresponding productioncount . So I wrote the DAX to take average of production of each code and sum it up to get the total production of day. 

 

NTest = 
var x = SUMX(SUMMARIZE(WASTAGE,(WASTAGE[CODE]), "SUMM", sum(WASTAGE[PRODUCTION])), [SUMM])
var y = count(WASTAGE[PRODUCTION])
return
x/y

NTest1 = 
VAR a = VALUES(WASTAGE[CODE] )
VAR Result = SUMX(a,[NTest])
RETURN 
IF(HASONEFILTER(WASTAGE[CODE]), [NTest], Result)

 

 

Now I need to calculate MTD and YTD using the same logic i.e, when i select a date, it needs to find the average production of each code, sum it up for all the days till the date selected. Any help is appreciated.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_1-1707199967621.png

 

MTD

MTD Average Production = 
VAR SelectedDate = MAX(WASTAGE[Date]) 
VAR MTDRange = DATESMTD(WASTAGE[Date])
RETURN
CALCULATE(
    [NTest1],
    MTDRange,
    FILTER(ALLSELECTED(WASTAGE), WASTAGE[Date] <= SelectedDate)
)

YTD

YTD Average Production = 
VAR SelectedDate = MAX(WASTAGE[Date])
VAR YTDRange = DATESYTD(WASTAGE[Date])
RETURN
CALCULATE(
    [NTest1],
    YTDRange,
    FILTER(ALLSELECTED(WASTAGE), WASTAGE[Date] <= SelectedDate)
)

Final output

vheqmsft_2-1707200328918.png

 

Best regards

Albert He

 

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

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_1-1707199967621.png

 

MTD

MTD Average Production = 
VAR SelectedDate = MAX(WASTAGE[Date]) 
VAR MTDRange = DATESMTD(WASTAGE[Date])
RETURN
CALCULATE(
    [NTest1],
    MTDRange,
    FILTER(ALLSELECTED(WASTAGE), WASTAGE[Date] <= SelectedDate)
)

YTD

YTD Average Production = 
VAR SelectedDate = MAX(WASTAGE[Date])
VAR YTDRange = DATESYTD(WASTAGE[Date])
RETURN
CALCULATE(
    [NTest1],
    YTDRange,
    FILTER(ALLSELECTED(WASTAGE), WASTAGE[Date] <= SelectedDate)
)

Final output

vheqmsft_2-1707200328918.png

 

Best regards

Albert He

 

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

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.