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
EmanuelTavares
Advocate II
Advocate II

Issue calculating variation of a value

Good morning,

 

I need to present a graphic with the sales variation month by month and I'm using the follow measure:

 

 

Variacao Mensal = 
IF(
	ISFILTERED(Pedidos[Data Criação]),
	ERROR("As medidas rápidas de análise de tempo só podem ser agrupadas ou filtradas pela hierarquia de data fornecida pelo Power BI ou pela coluna de datas primária."),
	VAR __PREV_MONTH = CALCULATE(SUM(ORDERS[total]), DATEADD(ORDERS[Created].[Date], -1, MONTH))
	RETURN DIVIDE(CALCULATE(SUM(ORDERS[total]), ORDERS[Created]) - __PREV_MONTH, __PREV_MONTH)
)

 

 

The calculation is fine, but when I put the measure in a graphic or table, it shows the "next month" with -100%.

 

Something like that:

 

Screenshot 2021-06-30 115736.png

 

I tried to redo the measure, filter the date, etc etc, but nothing works.

 

I verified the value of variable __PREV_MONTH using the follow measure:

 

 

PREVMONTH = 
	VAR __PREV_MONTH = CALCULATE(SUM(ORDERS[total]), DATEADD(Pedidos[Created].[Date], -1, MONTH))
    RETURN __PREV_MONTH

 

 

and, in fact, it returns a value for the month of July, that is the total sales of June. But June is the current month today.

 

Can anybody help me, please?

2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Would it work to add an IF(ISBLANK ... into your Return to check if one of your values is blank and return blank in that case?

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Hi @mahoneypat 

 

Thanks for the message.

 

Great idea!

 

I change the code to:

 

Variacao Mensal = 
IF(
	ISFILTERED(ORDERS[Created]),
	ERROR("As medidas rápidas de análise de tempo só podem ser agrupadas ou filtradas pela hierarquia de data fornecida pelo Power BI ou pela coluna de datas primária."),
	VAR __PREV_MONTH = CALCULATE(SUM(ORDERS[Created]), DATEADD(ORDERS[Created].[Date], -1, MONTH))
    VAR __CUR_MONTH = CALCULATE(SUM(ORDERS[total]), ORDERS[Created])
    VAR RESULT = IF(__CUR_MONTH, DIVIDE(__CUR_MONTH - __PREV_MONTH, __PREV_MONTH, 0))
	RETURN RESULT
)

 

and works very well.

 

Thanks again!

View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Would it work to add an IF(ISBLANK ... into your Return to check if one of your values is blank and return blank in that case?

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi @mahoneypat 

 

Thanks for the message.

 

Great idea!

 

I change the code to:

 

Variacao Mensal = 
IF(
	ISFILTERED(ORDERS[Created]),
	ERROR("As medidas rápidas de análise de tempo só podem ser agrupadas ou filtradas pela hierarquia de data fornecida pelo Power BI ou pela coluna de datas primária."),
	VAR __PREV_MONTH = CALCULATE(SUM(ORDERS[Created]), DATEADD(ORDERS[Created].[Date], -1, MONTH))
    VAR __CUR_MONTH = CALCULATE(SUM(ORDERS[total]), ORDERS[Created])
    VAR RESULT = IF(__CUR_MONTH, DIVIDE(__CUR_MONTH - __PREV_MONTH, __PREV_MONTH, 0))
	RETURN RESULT
)

 

and works very well.

 

Thanks again!

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors
Top Kudoed Authors