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
GraceN
Frequent Visitor

Get value from one month ago

Hi! I am new to Power BI, and I want to create a measure that returns a value corresponding to the previous month. I don't want to use a slicer. I think I want to use the CALCULATE function, but I don't know how to set it up.

 

Here is an Excel table with dummy data. It is now December and I want the values from November. In this example, I want measures to return Previous_Month_Actual = 52 and Previous_Month_Target = 55 

Thanks for your help

 

MonthActualTarget
01/31/1755
02/28/171210
03/31/171815
04/30/172120
05/31/172525
06/30/172730
07/31/173035
08/31/173940
09/30/174445
10/31/175350
11/30/175255
12/31/17 60
01/31/18 65
02/28/18 70
03/31/18 75
04/30/18 80
05/31/18 85
06/30/18 90

 

 

14 REPLIES 14
GraceN
Frequent Visitor

 Hi Wolf:

Thanks for the suggestion but inexplicably it's a partial solution. I was able to get the correct calculation for this specific example (although I need to change the semicolons in your formula to commas). On the other hand, I don't get the correct values with any other data set even when I used the same Excel table format for the source. That is,  I get unexpected values for  ActualLastMonth and TargetLastMonth, which are inconsistent, even though the values for ActualMeasure and TargetMeasure are correct. Here are 2 screenshots 1) the first dummy data set which worked, and 2) another dummy data set with the wrong values in the cards. I'm including the new measure in both

 

Dataset 1: this workedDataset 1: this workedDataset 2: this didn't workDataset 2: this didn't work

WolfBiber
Employee
Employee

Hi,

try following formula:

YourMeasure = CALCULATE(SUM(TheTable[Actual]); PREVIOUSMONTH(TheTable[Month]))

 

Greetings,

Wolf

Thanks, that partially worked. I created this measure, and I can see the last month's values in a new column in my table. 

 

On the other hand, I only want a scalar result that reflects the Actual or Target value for the previous month (rather than a new column of values). That is, I want the measure to show Actual_last_month = 52 and Target_last_month = 55

 

Capture2.PNG

Did you try the suggestion by @WolfBiber?  That uses a calculated measure so may be better suited to this


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Yes, I tried that. Please see my response in the previous message. 

GraceN
Frequent Visitor

To clarify, I want to display a single value from last month without the need for a slicer or selecting a row. When I use the card visualization, the value shows up as Blank. Only when I highlight a row in my table will the card show a value. I want my card to display last month's value of 52 for YourMeasure without having to click on 12/31/17 in the table.

 

 Capture4a.PNG 

In October, wieke ased the same question and there was no complete solution (even though it says Solved)

https://community.powerbi.com/t5/Desktop/Previous-month-value/m-p/266898/highlight/true#M120382

 

So just to clarify, you want the KPI that is showing as (blank) to show the latest value when nothing is selected, otherwise when a selection has been made, it's currently working perfectly?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

This might be getting close (with a few tweaks to suit)

 

YourMeasure = 
VAR LastDateWithalue = CALCULATE(LASTDATE('Table1'[Month]),'Table1'[Actual]<>BLANK())
VAR LatestValue =  CALCULATE(SUM('Table1'[Actual]),'Table1'[Month] = LastDateWithalue)
RETURN
IF(HASONEVALUE('Table1'[Month]),
				CALCULATE(
					SUM(Table1[Actual]), 
					PREVIOUSMONTH(Table1[Month])
					)
 	, LatestValue)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi Phil:

Thanks for your answer, but similar to srivint's measure, it only works for the Actual Last Month measure and not the Target Last Month measure. The Target column contains values to June 2018, and your measure returns a value of 90 rather than 55 

 

20171212b Capture.PNG

This should do the trick but you could tweak your DAX a bit to make it more concise and readable.

 

IF(

       HASONEVALUE('Table1'[Month]),

       CALCULATE( SUM(Table1[Actual]), PREVIOUSMONTH(Table1[Month]) ),

       CALCULATE( SUM(Table1[Actual]), CALCULATETABLE(LASTDATE(Table1[Month]), NOT(ISBLANK(Table1[Actual])))) 

)

Hi. Thanks for your solution, but it only works for the Actual Last Month measure because that field contains values only through Nov 2017, i.e. the previous month. The Target column shows values to June 2018 so your measure gives a value of 90 (rather than 55 which corresponds to Nov 2017).

 

20171212 Capture.PNG

Hey, you can use Filter with calculate an Today() function. Try the following expression:

 

LastMonth = CALCULATE([TheMeasure];Table1;month(Table1[Month])=MONTH(TODAY()))

 

Where TheMeasure is the same I posted:

TheMeasure = CALCULATE(SUM(Table1[Actual]); PREVIOUSMONTH(Table1[Month]))

 

Unbenannt.png

Greetings,

Wolf

Phil_Seamark
Employee
Employee

Hi @GraceN

 

If you are happy to add as a calculated column to your table.  You could try this.  Just repeate for target, but change the column used in the SUM function.  This assumes your previous value always falls on the last day of each month.

 

Previous Acutal = 
VAR D = 'Table1'[Month]
RETURN CALCULATE(SUM(Table1[Actual]),
            FILTER(ALL('Table1'),
                'Table1'[Month] =  DATE(YEAR(D),MONTH(d),1)-1
                )
                )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks but unfortunately I got this error message when I tried that

 

  • A single value for column 'Month' in table 'Sheet1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

 Capture.PNG

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.