Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
NielsDecoene
Helper I
Helper I

Getting my KPI's value only for the last Month

Hey guys,

 

I'm currently having somewhat of an issue at the moment:

I have a landings page for a company, they have several KPI's calculated there and are sliced by Month&Year on graphs.

Next to it is a KPI which shows comparison of this month's value in comparison to last month's one. 
Now if no specific month is selected for an argument, Power BI calculates the total of all months etc, which is not intended.

 

So what's  it they want:

A kpi (could be a card) that puts this Month's figure vs the Last one, if none are selected take the values for the latest Month:

Example of a KPI's code:
AffectedArticlesMonth = CALCULATE(
SUMX(FILTER(F_ComplaintTicket;[Quantity] >= 0); F_ComplaintTicket[Quantity]);
DATESBETWEEN(D_FilteredDate[DateFull].[Date];
FIRSTDATE(D_FilteredDate[DateFull].[Date]);
LASTDATE(D_FilteredDate[DateFull].[Date]));ALL(D_FilteredDate)
)

vs 

AffectedArticlesLastMonth = CALCULATE(
SUMX(FILTER(F_ComplaintTicket;[Quantity] >= 0); F_ComplaintTicket[Quantity]);
DATESBETWEEN(D_FilteredDate[DateFull].[Date];
FIRSTDATE(DATEADD(D_FilteredDate[DateFull].[Date]; -1; MONTH));
LASTDATE(DATEADD(D_FilteredDate[DateFull].[Date]; -1; MONTH)));ALL(D_FilteredDate))

Now i've tried using the following:
CALCULATE([AffectedArticlesMonth];FILTER(D_FilteredDate;MAX(D_FilteredDate[MonthId])))  

 

But DAX can't take Measures into it's expression:

 

The way i created a Title that does do the intended behaviour:
KPITitle =
VAR MaxMonthSeqNo = CALCULATE(MAX(D_FilteredDate[MonthId]))
Return LOOKUPVALUE(D_FilteredDate[MonthNameEn];D_FilteredDate[MonthId];MaxMonthSeqNo) & " " & LOOKUPVALUE(D_FilteredDate[YearId];D_FilteredDate[MonthId];MaxMonthSeqNo)

So if anyone has any ideas that can push me into the right direction, that'd be amazing.

Thanks in advance.

2 REPLIES 2
v-sihou-msft
Microsoft Employee
Microsoft Employee

@NielsDecoene

 

In this scenario, since your KPI is a measure, to show the last month's KPI measure, you can use DATEADD() function. The formula can be like:

 

Last Month KPI= CALCULATE([kpi measure], DATEADD(Table[Date],-1,MONTH))

 

Regards,

@v-sihou-msft

So in essence, your're forcing the measure to be sliced for a particular combination of Month.

The underlying variables can be ranging  dates from a year to quarter aggregations.
I'll test this out later today if i get the chance it looks promising so far.

 

My regards in  advance.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.