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

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
Employee
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
Employee
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
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.