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

Measure to get previous month data

I have a query could you pls help me to get this sorted. Have a slicer where it contains month as 22-08, 22-09, 22-10, 22-11, 22-12. Based on the slicer value selection I have to always get previous month data in the card. 
I tried using this measure but it only gives previous month data that is Nov month only but when I select 22-11 it should show Oct month data in the card.

CALCULATE(count(NGRReport[reportid]) ,MONTH(NGRReport[createdon])=(MONTH(TODAY())-1))

And the 2nd card which I have as current month data should show Nov month value when I select 22-11 in slicer

ChaitraS_0-1670563566079.png

 

 

Could you pls help me to get this sorted.
7 REPLIES 7
Anonymous
Not applicable

@lbendlin  I have tried using PREVIOUSMONTH function but dint get any data instead got Blank.

Slicer is in Year-month format (22-10). Used below measure, could you pls help me to correc it. Thanks in advance. 

CALCULATE(COUNT(NGRReport[reportid]), PREVIOUSMONTH(NGRReport[createdon]))

NGRReport[createdon] is in 08/26/2022 format which is been used in the measure & the slicer value is 22-10.
User wants the slicer to be in 22-10 format itself. 

Sounds like your data model is missing the calendar table? These functions require a correctly set up and linked calendar table.

Anonymous
Not applicable

I have the Calendar table linked with NGRReport table which is been used in the measure.
I tried taking Created month column as slicer value in date format & got the expected results using PREVIOUSMONTH. But one issue is when the slicer is selected as ALL it shows same values in current month, overall report generated & blank in previous month card.
Could you pls help how to sort this.

Always the slicer selection should be as ALL & there are other visuals in the report to show data as Overall. 

ChaitraS_3-1671007931456.png

 

ChaitraS_1-1671007854786.png

 

ChaitraS_2-1671007881062.png

 

When you set Created Month to "All" the concept of a previous month no longer applies. Rethink what you are trying to achieve.

Anonymous
Not applicable

Ok got it thanks. 
The measure which I used to get previous month data doesnt show correct data. Could you pls help me on this.

Measure used - 

CALCULATE(COUNT(NGRReport[reportid]), PREVIOUSMONTH(NGRReport[Date]))
ForNov - 
ChaitraS_0-1671423499682.png


Supposed to get 63 in place of 10 here 

ChaitraS_1-1671423529194.png

I have Date table as well in model & connected. 
Slicer created on is date column from NGRReport 

Change your PREVIOUSMONTH  function to use the date from the calendar table.

lbendlin
Super User
Super User

You must use YearMonth format, and you cannot do math like that. MONTH(TODAY())-1 will fail in January.

 

Use PREVIOUSMONTH or DATEADD built-in functions.

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.

Top Solution Authors
Top Kudoed Authors