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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

sum of deviation in relation to previous month

 

Hi everyone

I have a problem and I can not solve it.
I have a table like this:

Rick_ferreira_0-1622452637683.png

I need to build a graph with a sum of deviation in relation to previous month. To count the deviation I need to consider always the max – min between the current month and the previous month
For example, to February:

Rick_ferreira_1-1622452670578.png

And finally, I need to create the chart like this:

Rick_ferreira_2-1622452716044.png

I am trying but probably I am doing something wrong-

Does someone help me?

3 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@Anonymous 

Create a Date table as it will help you with the time intelligence functions. Check the attached file.

Fowmy_0-1622455505140.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

I suggest having a dim-calendar table like below.

please check the below picture and the sample pbix file's link down below.

 

Picture1.png

 

Number of Sales Total =
SUM(Sales[No of Sales])
 
Deviation =
SUMX (
CROSSJOIN ( VALUES ( 'Calendar'[Month & Year] ), VALUES ( Sales[Product] ) ),
IF (
ISBLANK (
CALCULATE ( [Number of Sales Total], DATEADD ( 'Calendar'[Date], -1, MONTH ) )
),
BLANK (),
ABS (
[Number of Sales Total]
- CALCULATE ( [Number of Sales Total], DATEADD ( 'Calendar'[Date], -1, MONTH ) )
)
)
)
 
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

Hi, @Anonymous 

Please check the below.

 

Picture3.png

 

deviation CC =
VAR currentdate = Sales[Date]
VAR currentproduct = Sales[Product]
VAR previousdate =
CALCULATE (
MAX ( Sales[Date] ),
FILTER ( Sales, Sales[Product] = currentproduct && Sales[Date] < currentdate )
)
VAR previousnoofsales =
CALCULATE (
SUM ( Sales[No of Sales] ),
FILTER ( Sales, Sales[Product] = currentproduct && Sales[Date] = previousdate )
)
RETURN
IF (
NOT ISBLANK ( previousnoofsales ),
ABS ( Sales[No of Sales] - previousnoofsales )
)
 
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

8 REPLIES 8
Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

I suggest having a dim-calendar table like below.

please check the below picture and the sample pbix file's link down below.

 

Picture1.png

 

Number of Sales Total =
SUM(Sales[No of Sales])
 
Deviation =
SUMX (
CROSSJOIN ( VALUES ( 'Calendar'[Month & Year] ), VALUES ( Sales[Product] ) ),
IF (
ISBLANK (
CALCULATE ( [Number of Sales Total], DATEADD ( 'Calendar'[Date], -1, MONTH ) )
),
BLANK (),
ABS (
[Number of Sales Total]
- CALCULATE ( [Number of Sales Total], DATEADD ( 'Calendar'[Date], -1, MONTH ) )
)
)
)
 
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thank you so much.

I tried to do your advice but insted of create a measure I am creating a column using dax to add on table the desviation column but your rule doesn´t work.

Could you please explain me why?

Thanks

Hi, @Anonymous 

Thank you for your feedback.

I think you cannot use the formula for creating a column that is for creating a measure.

how does your expected outcome look like?

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

I would like to create a new column with desviation as your measure do. I want to create a columns like this:

Rick_ferreira_0-1622465483560.png

 

Hi, @Anonymous 

Please check the below.

 

Picture3.png

 

deviation CC =
VAR currentdate = Sales[Date]
VAR currentproduct = Sales[Product]
VAR previousdate =
CALCULATE (
MAX ( Sales[Date] ),
FILTER ( Sales, Sales[Product] = currentproduct && Sales[Date] < currentdate )
)
VAR previousnoofsales =
CALCULATE (
SUM ( Sales[No of Sales] ),
FILTER ( Sales, Sales[Product] = currentproduct && Sales[Date] = previousdate )
)
RETURN
IF (
NOT ISBLANK ( previousnoofsales ),
ABS ( Sales[No of Sales] - previousnoofsales )
)
 
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Fowmy
Super User
Super User

@Anonymous 

Create a Date table as it will help you with the time intelligence functions. Check the attached file.

Fowmy_0-1622455505140.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

selimovd
Super User
Super User

Hey @Anonymous ,

 

you can calculate the value from the last month and subtract that from the current month:

Deviation Last Month = SUM( myTable[No of Sales] ) - CALCULATE( SUM( myTable[No of Sales] ), DATEADD( myTable[Date], -1, MONTH ) )

 

This should work for your case.

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
Anonymous
Not applicable

Hello
Thanks, but you resolution doesn´t work.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.