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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Mramono
Helper III
Helper III

Average Week to date (WTD) ignoring blanks and zeros (dax Measure)

Hello Friend

I have tried everything i know by know to try come up with the Measure that can calculate Week to date (WTD) AVERAGE. Unfortunately all the help i found in my research does not work. I don't know why. I hope someone can take me out of this misery.

 

I provide a link to my data table

https://docs.google.com/spreadsheets/d/1g_EMyXXKf8sb_xRQNBRcxseietRQ5YRC/edit?usp=drive_link&ouid=10...

 

Basically I need Dynamic WEEK TO DATE (WTD) average based on date slicer for "Prod Quality (%)" in my data table (ProdData2). I have managed to get dynamic WTD sum for the "Prod Tonnes"

 

I will appreciate help Please!!

Kind regards

mramono

1 ACCEPTED SOLUTION

Hi @Mramono ,

Thank you for the update.  I have created two measures WTD_Avg_Quality and  WTD_NonZeroCount. Please refer below 

 

1.

WTD_Avg_Quality =
VAR CurrentDate = MAX ( 'Date'[Date] )
VAR StartOfWeek = CurrentDate - ( WEEKDAY ( CurrentDate, 2 ) - 1 )

VAR WTD_Data =
    FILTER (
        ALL ( ProdData2 ),
        ProdData2[Production Date] >= StartOfWeek
            && ProdData2[Production Date] <= CurrentDate
            && NOT ISBLANK ( ProdData2[Prod Quality (%)] )
            && ProdData2[Prod Quality (%)] <> 0
    )

RETURN
AVERAGEX ( WTD_Data, ProdData2[Prod Quality (%)] )
 
2. 
 
WTD_NonZeroCount =
VAR CurrentDate = MAX ( 'Date'[Date] )
VAR StartOfWeek = CurrentDate - ( WEEKDAY ( CurrentDate, 2 ) - 1 )

VAR WTD_Data =
    FILTER (
        ALL ( ProdData2 ),
        ProdData2[Production Date] >= StartOfWeek
            && ProdData2[Production Date] <= CurrentDate
            && NOT ISBLANK ( ProdData2[Prod Quality (%)] )
            && ProdData2[Prod Quality (%)] <> 0
    )

RETURN
COUNTROWS ( WTD_Data )
 
Please refer below output snap and attached PBIX file.
 
vdineshya_0-1760424418465.png

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

View solution in original post

7 REPLIES 7
Irwan
Super User
Super User

hello @Mramono 

 

i assumed WTD is a running sum for a week.

Irwan_0-1760308874738.png

 

please check if this accomodate your need.

1. create a new table for calendar date.

Irwan_1-1760308918322.png

 

2. create a relationship between calendar and your fact table.

Irwan_2-1760308950072.png

 

3. create a new measure with following DAX to calculate WTD for same week and year.

WTD =
SUMX(
    FILTER(
        ALL('Table'),
        'Table'[Production Date]<=MAX('Calendar'[Date])&&
        WEEKNUM('Table'[Production Date])=SELECTEDVALUE('Calendar'[Week])&&
        YEAR('Table'[Production Date])=SELECTEDVALUE('Calendar'[Year])
    ),
    'Table'[Prod Tonnes]
)
 
Hope this will help.
Thank you.

@Irwan thank you for the running sum, however i am mostly struggling with Running AVERAGE. Basically Running sum divided by number of rows in a running week (where the rows are non zeros and non blank)

 

I guess we need a dax that can COUNT ROWS that are non zero and non blank for the running week.

hello @Mramono 

 

if you need running average, you can change SUMX into AVERAGEX.

if you need to exclude non-blank and zero value, then you can add more filter into the DAX.

Irwan_0-1760394181887.png

Thank you.

Hi @Mramono ,

Thank you for reaching out to the Microsoft Community Forum.

 

As you mentioned in your previous post, you want a DAX measure that can COUNT ROWS that are non zero and non blank for the running week.

 

Please refer below DAX measure.

 

WTD Avg Quality =
VAR CurrentDate = MAX ( 'DateTable'[Date] )
VAR CurrentWeek = MAX ( 'DateTable'[YearWeek] )

VAR WTD_Table =
    FILTER (
        ALL ( 'DateTable' ),
        'DateTable'[YearWeek] = CurrentWeek &&
        'DateTable'[Date] <= CurrentDate
    )

VAR WTD_Data =
    FILTER (
        ProdData2,
        ProdData2[Production Date] IN SELECTCOLUMNS ( WTD_Table, "Date", 'DateTable'[Date] ) &&
        NOT ISBLANK ( ProdData2[Prod Quality (%)]) &&
        ProdData2[Prod Quality (%)] <> 0
    )

VAR Sum_Quality = SUMX ( WTD_Data, ProdData2[Prod Quality (%)] )
VAR Count_Quality = COUNTROWS ( WTD_Data )

RETURN
DIVIDE ( Sum_Quality, Count_Quality )
 
Please refer below output snap and attached PBIX file.
 
vdineshya_0-1760350274807.png

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

Hi @v-dineshya thank you very much for coming in to assist. Unfortunately i don't quite get the right answer. E.g. on the first week of the year in the my data, when i just use excel to get average for the first week the answer is 35.83 but in power bi on the script you graciously provided the answer is 33.02. I basically used a date slicer and chose 5th Jan, I assumed it will give me the average from the begining of the year to the 5th Jan.

 

Is it possible to make a separate measure that only count rows excluding zeros and blanks for Week to date?

Mramono_0-1760392816804.png

 

 

Hi @Mramono ,

Thank you for the update.  I have created two measures WTD_Avg_Quality and  WTD_NonZeroCount. Please refer below 

 

1.

WTD_Avg_Quality =
VAR CurrentDate = MAX ( 'Date'[Date] )
VAR StartOfWeek = CurrentDate - ( WEEKDAY ( CurrentDate, 2 ) - 1 )

VAR WTD_Data =
    FILTER (
        ALL ( ProdData2 ),
        ProdData2[Production Date] >= StartOfWeek
            && ProdData2[Production Date] <= CurrentDate
            && NOT ISBLANK ( ProdData2[Prod Quality (%)] )
            && ProdData2[Prod Quality (%)] <> 0
    )

RETURN
AVERAGEX ( WTD_Data, ProdData2[Prod Quality (%)] )
 
2. 
 
WTD_NonZeroCount =
VAR CurrentDate = MAX ( 'Date'[Date] )
VAR StartOfWeek = CurrentDate - ( WEEKDAY ( CurrentDate, 2 ) - 1 )

VAR WTD_Data =
    FILTER (
        ALL ( ProdData2 ),
        ProdData2[Production Date] >= StartOfWeek
            && ProdData2[Production Date] <= CurrentDate
            && NOT ISBLANK ( ProdData2[Prod Quality (%)] )
            && ProdData2[Prod Quality (%)] <> 0
    )

RETURN
COUNTROWS ( WTD_Data )
 
Please refer below output snap and attached PBIX file.
 
vdineshya_0-1760424418465.png

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

Thank you so much @v-dineshya this works wonders, your dax code is doing exactly what i need.

Very much oblidged!!!

mramono

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors