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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
EmanuelTavares
Advocate I
Advocate I

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.