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! Request now

Reply
WaelTalaat79
Helper I
Helper I

Message error

Message Error.JPG

 

i am trying to calculate the previous month but it is always show an error  as screen attached

the fromula is 

PrevMonth = IF(MONTH(PREVIOUSMONTH('Date'[Date].[MonthNo]))=12,0,1)
i need to che

 

 

 

Feedback Type:
Frown (Error)

Timestamp:
2022-05-30T11:05:30.5171689Z

Local Time:
2022-05-30T13:05:30.5171689+02:00

Session ID:
ce8e093f-0b2a-4a3d-8e27-0db256fad5fb

Release:
May 2022

Product Version:
2.105.664.0 (22.05) (x64)

OS Version:
Microsoft Windows NT 10.0.19041.0 (x64 en-US)

CLR Version:
4.8 or later [Release Number = 528372]

Peak Virtual Memory:
56.2 GB

Private Memory:
1.51 GB

Peak Working Set:
1.53 GB

IE Version:
11.789.19041.0

User ID:
405012b2-9843-43cc-814a-12c77f1e1a24

Workbook Package Info:
1* - en-US, Query Groups: 4, fastCombine: Disabled, runBackgroundAnalysis: False.

Telemetry Enabled:
True

Model Default Mode:
Import

Model Version:
PowerBI_V3

Enabled Preview Features:
PBI_shapeMapVisualEnabled
PBI_SpanishLinguisticsEnabled
PBI_qnaLiveConnect
PBI_azureMapVisual
PBI_compositeModelsOverAS
PBI_enhancedTooltips
PBI_enableWebView2
PQ_WebView2Connector
PBI_mobileAuthoringFormattingUI
PBI_useModernFormatPane
PBI_sparklines
PBI_scorecardVisual
PBI_lineChartError
PBI_fieldParametersSuperSwitch

Disabled DirectQuery Options:
TreatHanaAsRelationalSource

Cloud:
GlobalCloud

DPI Scale:
125%

Supported Services:
Power BI

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @WaelTalaat79 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:

Net impact of the month = 
VAR _selym =
    SELECTEDVALUE ( 'Date'[YearMonth] )
VAR _premonthvalue =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        YEAR ( 'Table'[Date] ) = VALUE ( LEFT ( _selym, 4 ) ),
        PREVIOUSMONTH ( 'Date'[Date] ),
        ALL ( 'Table' )
    )
VAR _curmonthvalue =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        YEAR ( 'Table'[Date] ) = VALUE ( LEFT ( _selym, 4 ) )
            && MONTH ( 'Table'[Date] ) = VALUE ( RIGHT ( _selym, 2 ) )
    )
RETURN
    IF ( ISBLANK ( _premonthvalue ), 0, _curmonthvalue - _premonthvalue )

yingyinr_0-1654155317077.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

6 REPLIES 6
Tahreem24
Super User
Super User

@WaelTalaat79 You can create a Calculated Column like this:

Prev Month No. Column= MONTH(DATEADD('Calendar'[Date],-1,MONTH))
 
Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard
AntonioM
Solution Sage
Solution Sage

PREVIOUSMONTH doesn't work that way unfortunately. It takes a column of dates and gives you the same column back but all one month earlier. 

 

You'd need to use it something like

CALCULATE( [Measure], PREVIOUSMONTH( 'Date Table'[Date] ) )

 

What is it PrevMonth is trying to check?

Let say the 12 monthes from Jan to Dec

So if i asked to get the Monthname of the previous Ex  main Month Jan --- previous month Dec.

so i need a fromula to if the previous month is December put Zero instaed if not return value for the previous month

Do you just want to know what month, or is there a calculation you want to calculate for last month?

I need to subtract the currnt YTD month revenue - YTD previous month to get the net impact of the month

but the problem is that Jan consider the previous month is Dec same year 

so I need if the equation to put zero in case of Dec

Anonymous
Not applicable

Hi  @WaelTalaat79 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:

Net impact of the month = 
VAR _selym =
    SELECTEDVALUE ( 'Date'[YearMonth] )
VAR _premonthvalue =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        YEAR ( 'Table'[Date] ) = VALUE ( LEFT ( _selym, 4 ) ),
        PREVIOUSMONTH ( 'Date'[Date] ),
        ALL ( 'Table' )
    )
VAR _curmonthvalue =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        YEAR ( 'Table'[Date] ) = VALUE ( LEFT ( _selym, 4 ) )
            && MONTH ( 'Table'[Date] ) = VALUE ( RIGHT ( _selym, 2 ) )
    )
RETURN
    IF ( ISBLANK ( _premonthvalue ), 0, _curmonthvalue - _premonthvalue )

yingyinr_0-1654155317077.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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
Top Kudoed Authors