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 Months data column

Hi all,

 

I have a small table summarised of another table. I would like to show the current months data and previous months on the same line/row in the table. I have managed to do this for the previous month using the PREVIOUSMONTH function, however would like to also show the previous months total value on the same line. I have used the following DAX syntax, however it's not worked as expected:

 

Total Previous Month Value = ROUND(CALCULATE('Summary Table'[Total Calculated Value],PREVIOUSMONTH('Summary by Month'[Previous Month].[Date])),2)
 
My table is below:
 
jamesbruty_0-1623742662675.png

On the Report Date of 01 December 2020 line, I would like the Total Previous Months Value to be blank (as 01 November 2020 is blank), then for 01 January Report Date (01 December 2020 Previous Month), for the column to show 375622.08 etc...

 

I hope this makes sense and would be very grateful for any advise 🙂

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Please update the formula of your measure [Prev Month Value] as below and check whether it works or not:

Prev Month Value = 
VAR _curdate =
    SELECTEDVALUE ( 'Summary by Network Operator'[Report Date] )
VAR _lastmonth =
    IF ( MONTH ( _curdate ) = 1, 12, MONTH ( _curdate ) - 1 )
VAR _year =
    IF ( MONTH ( _curdate ) = 1, YEAR ( _curdate ) - 1, YEAR ( _curdate ) )
RETURN
    CALCULATE (
        ROUND ( SUM ( 'Summary by Network Operator'[Total by Month] ), 2 ),
        FILTER (
            ALLSELECTED ( 'Summary by Network Operator' ),
            YEAR ( 'Summary by Network Operator'[Report Date] ) = _year
                && MONTH ( 'Summary by Network Operator'[Report Date] ) = _lastmonth
        )
    )

yingyinr_0-1624002090820.png

If the above one still not working in your scenario, please provide some sample data with Text format and expected result with specific examples and calculation logic. Thank you.

Best Regards

Community Support Team _ Rena
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

8 REPLIES 8
Anonymous
Not applicable

Hi,

 

I am now trying to create an additional table summarised at a higher level (Network Operator) and create the same kind of table as above. I have linked the Calendar to this summarised table and the 'Previous Month' syntax has worked (

Previous Month = PREVIOUSMONTH('Summary by Network Operator'[Report Date])), however when I try and pull through the values from the previous month using the following syntax, it doesn't:
jamesbruty_0-1623833090972.png

I'm trying to get the values for the previous month by Netowk Operator, any help again (@HashamNiaz) would be grately appreciated! 🙂

 

Thanks

 

James

Hi @Anonymous !

 

Please check if you have a active relationship between your Date / Calendar table with your (Summary by Network Operator) fact table based on [Report Date] column. Now in your matrix / table visual use Date from Calendar dimension.

 

Regards,

Hasham

Anonymous
Not applicable

Hi @HashamNiaz ,

 

Yes, there is an active relationship between the two tables:

jamesbruty_1-1623836071625.png

Thanks for getting back to me! 🙂

 

James

Hi @Anonymous !

 

Did it solved when you placed the [Date] column from Calendar dimesio instead of using [Report Date] from your fact (Summary with Network operator) table.

 

Regards,

Hasham

Anonymous
Not applicable

Hi @HashamNiaz ,

Unfortunately not, I have tried using both the Report Date & Date from the Calendar table and neither work, syntax for both below:

 

Prev Month Value = CALCULATE(ROUND(SUM('Summary by Network Operator'[Total by Month]),2),DATEADD('Summary by Network Operator'[Report Date],-1,MONTH))
 
Prev Month Value = CALCULATE(ROUND(SUM('Summary by Network Operator'[Total by Month]),2),DATEADD('Calendar'[Date],-1,MONTH))
 

Thanks

James

Hi @Anonymous ,

Please update the formula of your measure [Prev Month Value] as below and check whether it works or not:

Prev Month Value = 
VAR _curdate =
    SELECTEDVALUE ( 'Summary by Network Operator'[Report Date] )
VAR _lastmonth =
    IF ( MONTH ( _curdate ) = 1, 12, MONTH ( _curdate ) - 1 )
VAR _year =
    IF ( MONTH ( _curdate ) = 1, YEAR ( _curdate ) - 1, YEAR ( _curdate ) )
RETURN
    CALCULATE (
        ROUND ( SUM ( 'Summary by Network Operator'[Total by Month] ), 2 ),
        FILTER (
            ALLSELECTED ( 'Summary by Network Operator' ),
            YEAR ( 'Summary by Network Operator'[Report Date] ) = _year
                && MONTH ( 'Summary by Network Operator'[Report Date] ) = _lastmonth
        )
    )

yingyinr_0-1624002090820.png

If the above one still not working in your scenario, please provide some sample data with Text format and expected result with specific examples and calculation logic. Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
HashamNiaz
Solution Sage
Solution Sage

Hi @Anonymous !

 

Please use following DAX to get previous month value;

 

Prev Month Value = CALCULATE([Total Calculated Value], DATEADD(Calendar[Date],-1,MONTH))

 

You need to have Calendar dimension in your data model & connect your Calendar dimension with your Summary fact table based on Date Key.

 

Regards,

Hasham

Anonymous
Not applicable

Many thanks Hasham, worked a treat!! 🙂

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.