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
GarlonYau
Helper I
Helper I

Changing Values to 0 after a specified date in Dax Table

Hi There! I've been stuck on this problem for a while, so any help is appreciated!

I've got a DAX measure that calculates a rolling 3 month average around Absenteeism numbers.

Here's the formula I've been using and it's working so far, when I show it in a table.

 

 

Moving 3 Months Average = 
VAR temp =
    CALCULATE (
        AVERAGEX (
                SUMMARIZE (
                'Summarized Time Off Request',
                'DateTable'[Date].[Year],
                'DateTable'[Date].[Month],
                "sumtotal", [Absenteeism (All) %]
            ),
            [sumtotal]
        ),
        DATESINPERIOD (
            'DateTable'[Date],
            LASTDATE ( 'DateTable'[Date] ),
            -3,
            MONTH
        )
    )
RETURN
   temp

 

 

GarlonYau_0-1658186442223.png

 

However, I can't seem to figure out what I need to change to the formula to make any returned value AFTER Dec 31, 2021 to = 0 (would be the part indicated in red).
Reason for this is because I'm merging an old data set with hardcoded monthly numbers and a new data set coming from a system.

 

Thanks for you help in advance!

1 ACCEPTED SOLUTION

Hi @GarlonYau ,

Please have a try.

Modify your measure.

Moving 3 Months Average = 
VAR temp =
    CALCULATE (
        AVERAGEX (
                SUMMARIZE (
                'Summarized Time Off Request',
                'DateTable'[Date].[Year],
                'DateTable'[Date].[Month],
                "sumtotal", [Absenteeism (All) % Historical]
            ),
            [sumtotal]
        ),
        DATESINPERIOD (
            'DateTable'[Date],
            LASTDATE ( 'DateTable'[Date] ),
            -3,
            MONTH
        )
    )
RETURN
If(max('datetable'[date]<date(2022,1,1),tmep,0)

If it still doesnot help, please provide your pbix file without privacy information and desired output with more details. (Or some sample data).

 

Best Regards
Community Support Team _ Polly

 

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

3 REPLIES 3
GarlonYau
Helper I
Helper I

@amitchandak  Thanks for your reply!

 

Your advice worked somewhat. However, any month with no data now yields the value 6.52% for some odd reason.

 

Here's the measure.

Moving 3 Months Average = 
VAR temp =
    CALCULATE (
        AVERAGEX (
                SUMMARIZE (
                'Summarized Time Off Request',
                'DateTable'[Date].[Year],
                'DateTable'[Date].[Month],
                "sumtotal", [Absenteeism (All) % Historical]
            ),
            [sumtotal]
        ),
        DATESINPERIOD (
            'DateTable'[Date],
            LASTDATE ( 'DateTable'[Date] ),
            -3,
            MONTH
        )
    )
RETURN
   if(max('DateTable'[Date]) >= Date(2022,01,01) , 0 , temp)

 

And here's the measure for [Absenteeism (All) % Historical]

Absenteeism (All) % Historical = CALCULATE(AVERAGE('Summarized Time Off Request'[Value]),'Summarized Time Off Request'[Metric]="Absenteeism (All)")

 

GarlonYau_0-1658198372242.png

 

Hi @GarlonYau ,

Please have a try.

Modify your measure.

Moving 3 Months Average = 
VAR temp =
    CALCULATE (
        AVERAGEX (
                SUMMARIZE (
                'Summarized Time Off Request',
                'DateTable'[Date].[Year],
                'DateTable'[Date].[Month],
                "sumtotal", [Absenteeism (All) % Historical]
            ),
            [sumtotal]
        ),
        DATESINPERIOD (
            'DateTable'[Date],
            LASTDATE ( 'DateTable'[Date] ),
            -3,
            MONTH
        )
    )
RETURN
If(max('datetable'[date]<date(2022,1,1),tmep,0)

If it still doesnot help, please provide your pbix file without privacy information and desired output with more details. (Or some sample data).

 

Best Regards
Community Support Team _ Polly

 

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

amitchandak
Super User
Super User

@GarlonYau , You can add code in return

if(max('DateTable'[Date]) >= Date(2022,01,01) , 0 , temp)

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.