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
Anonymous
Not applicable

Tabular Editor (Previous Months measure sometimes is the total of previous months)

Hello friends, I'm using Tabular Editor to build a calculation group for Previous Month (later MOM, YOY etc), 

But when I tried it in the report, it shows like this:

ANC2527_0-1603389730587.png

It looks like sometimes the PreviousMonth data is a total of couple of months😣

Below is my calcaulation group and calcaulation items:

 

ANC2527_1-1603389845247.png

This is the Expression for Current and PreviousMonth:

  • Current Month: 
SelectedMeasure ()

ANC2527_5-1603390089620.png

 

  • Previous Month:
CALCULATE ( SELECTEDMEASURE (), DATEADD ( 'dimdate'[FiscalDate], -1, MONTH ) )

ANC2527_6-1603390145514.png

below is how the date date looks like:

ANC2527_4-1603389966242.png

 

Which part did I do wrong?

 

Thank you 🤔

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hello @ANC2527

The reason for this behavior appears to be related to how your Periods are defined.

Since there are 8 per year, do I take that each Period is approximately 45 days?

This means that subtracting one month from the dates of a Period using DATEADD will not be the same as changing the dates by a Period. Depending on the dates on which the values appear, you may see the values of several periods included when you change the dates earlier by one month.

I think you'll need to write DAX to capture your requirements instead of using DATEADD.

If you create a column in the dimdate table named Year Period Number that acts as a Year/Period index, so that it is incremented by one for each period, you could write code similar to the sales PM measure in the Month-to-Month Growth section of this article:

https://www.daxpatterns.com/month-related-calculations/

For the PreviousMeh calculation element, it would look something like:

VAR CurrentYearPeriodNumber = SELECTEDVALUE ( 'dimdate'[Year Period Number] )
VAR PreviousYearPeriodNumber = CurrentYearPeriodNumber - 1
VAR Result =
    CALCULATE (
        SELECTEDMEASURE (),
        REMOVEFILTERS ( 'dimdate' ),
        'dimdate'[Year Period Number] = PreviousYearPeriodNumber
    )
RETURN
    Result

Best regards

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

Hello @ANC2527

The reason for this behavior appears to be related to how your Periods are defined.

Since there are 8 per year, do I take that each Period is approximately 45 days?

This means that subtracting one month from the dates of a Period using DATEADD will not be the same as changing the dates by a Period. Depending on the dates on which the values appear, you may see the values of several periods included when you change the dates earlier by one month.

I think you'll need to write DAX to capture your requirements instead of using DATEADD.

If you create a column in the dimdate table named Year Period Number that acts as a Year/Period index, so that it is incremented by one for each period, you could write code similar to the sales PM measure in the Month-to-Month Growth section of this article:

https://www.daxpatterns.com/month-related-calculations/

For the PreviousMeh calculation element, it would look something like:

VAR CurrentYearPeriodNumber = SELECTEDVALUE ( 'dimdate'[Year Period Number] )
VAR PreviousYearPeriodNumber = CurrentYearPeriodNumber - 1
VAR Result =
    CALCULATE (
        SELECTEDMEASURE (),
        REMOVEFILTERS ( 'dimdate' ),
        'dimdate'[Year Period Number] = PreviousYearPeriodNumber
    )
RETURN
    Result

Best regards

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

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.