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

Previous month measure figure is not correct

Hi,

I am trying get previous month figures, but it the DAX i have does not show the correct figure.

I have 3 measures:

 

Measure1 (correct):

-----------

Total List Price = CALCULATE(SUM(Purchases[Line Amount]), FILTER(Purchases, Purchases[General Product Posting Group] IN {"PART", "PART-SC"} && Purchases[Part Number] <> ""))
 

Measure2 (correct):

-----------

Testing WA Price Monthly =
VAR AnnualListPrice =CALCULATE([Total List Price], ALL('Posting Date'[FY Month Name Short], 'Posting Date'[FY Month]))
VAR MonthlyTable =
ADDCOLUMNS(
SUMMARIZE(
Purchases,
'Posting Date'[FY], 'Posting Date'[FY Month Name Short]
),
"MonthlyPrice", [Total List Price],
"WT", DIVIDE([Total List Price], AnnualListPrice)
)
Return
SUMX(
MonthlyTable,
[Wt]* [MonthlyPrice]
)
 

Measure3 (incorrect):

This measure shows the value of measure [Total List Price] instead [Testing WA Price Monthly]

-----------

Testing WA Price Monthly Prev =
CALCULATE([Testing WA Price Monthly]
, dateadd( 'Posting Date'[Date], -1,MONTH))
 

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

Please try this Measure.

 

Testing WA Price Monthly Prev =

VAR max_date =

    MAX ( 'Posting date'[Date] )

VAR max_month =

    MONTH ( max_date )

VAR max_year =

    YEAR ( max_date )

VAR year =

    IF ( max_month = 1, max_year - 1, max_year )

VAR month =

    IF ( max_month = 1, 12, max_month - 1 )

VAR res =

    CALCULATE (

        [Testing WA Price Monthly],

        FILTER (

            ALL ( 'Posting date' ),

            YEAR ( 'Posting date'[Date] ) = year

                && MONTH ( 'Posting date'[Date] ) = month

        )

    )

RETURN

    res

The result looks like this:

v-cazheng-msft_0-1617774554917.png

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? 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

5 REPLIES 5
v-cazheng-msft
Community Support
Community Support

Hi @Anonymous 

Please try this Measure.

 

Testing WA Price Monthly Prev =

VAR max_date =

    MAX ( 'Posting date'[Date] )

VAR max_month =

    MONTH ( max_date )

VAR max_year =

    YEAR ( max_date )

VAR year =

    IF ( max_month = 1, max_year - 1, max_year )

VAR month =

    IF ( max_month = 1, 12, max_month - 1 )

VAR res =

    CALCULATE (

        [Testing WA Price Monthly],

        FILTER (

            ALL ( 'Posting date' ),

            YEAR ( 'Posting date'[Date] ) = year

                && MONTH ( 'Posting date'[Date] ) = month

        )

    )

RETURN

    res

The result looks like this:

v-cazheng-msft_0-1617774554917.png

 

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

this is what I want:

2021-04-05_13-42-53.png

@Anonymous , Try with date table , marked as date table , and use month from date table in visual

 

Testing WA Price Monthly Prev =
CALCULATE([Testing WA Price Monthly]
, dateadd( 'Date'[Date], -1,MONTH))

 

Also refer why TI failes - https://www.youtube.com/watch?v=OBf0rjpp5Hw

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Anonymous
Not applicable

I just check the tabular model, 'Posting Date' is marked as date table.

Anonymous
Not applicable

Thanks @amitchandak , the table 'Posting Date' I am using is a date table and I am using the month form 'Posting Date' table. I am not sure what do you mean by "marked as a date table".

My data source is tabular model.

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.