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
Tasnalem
Regular Visitor

Create a table/matrix where rows and colums are the same field and the values are the difference

Hi,

 

I am trying to show the difference of the VALUE column month by month. I explain:

 

This is my dataset. I have two columns, one is the column "value_date" in format dd/mm/yyyy and the other one is the column "value" with the decimal value.

 

Tasnalem_0-1703579702140.png

 

The business goal is create this table/matriz in Power BI to compare VALUE column between months, for example, if the sum of January is = 1000 and sum of February is 800, the value in the table will be 200 ( or -200).

SUM( value, value_date =  "JANUARY") - SUM( value, value_date =  "FEBRUARY")

 

As you can see, the diagonal will be always 0, because you are always compare the same month with itself

 

 JanuaryFebruaryMarch[....] NovemberDecember
January020,5 ( January - February )7,6 ( January - March)5,41012,3
February-20,5087,22,75,9
March-7,6804,91,20,9
 [....] -5,4-7,2-4,907,65,9
November-10-2,7-1,2-7,601

December

-12,3-5,9-0,9-5,9-1

0

 

Any idea?

 

Thansk in advance

7 REPLIES 7
ERD
Super User
Super User

@Tasnalem , not sure this is what you need, but you can try this approach:

1. Create a second Date table.

ERD_0-1703612277482.png

2. Use both in Matrix visual.

3. Create a measure:

test = 
var m_1 = SELECTEDVALUE('Date'[YYYYMM])
var m_2 = SELECTEDVALUE(Date_2[YYYYMM])
var x1 = CALCULATE(SUM(Data[Value]), REMOVEFILTERS('Date_2') )
var x2 = CALCULATE(SUM(Data[Value]), REMOVEFILTERS('Date') )
return 
x1-x2

Data:

ERD_1-1703612316608.png

Result:

ERD_2-1703612346263.png

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Hello,

 

Thank you for your help. but with this solution I have a table only with a diagonal with "0". I don't have the difference between differents months:

Tasnalem_0-1703664734959.png

 

v-zhengdxu-msft
Community Support
Community Support

Hi @Tasnalem 

 

I have understood your problem.

You need to create a matrix with rows and columns that are months, and the values in the table are the difference between the values of the month.

Here is the solution:

First, I created a set of reference data.

vzhengdxumsft_0-1703575427434.png

Then, extract the month.

With the DAX:

------------------------------------------------------------

Month = FORMAT([value_date],"mmmm")

------------------------------------------------------------

vzhengdxumsft_1-1703575427436.pngvzhengdxumsft_2-1703575474175.png

Then, a table 2 is created based on the value and month of Table 1

------------------------------------------------------------

Table 2 = SELECTCOLUMNS('Table',[Month],[value])

------------------------------------------------------------

vzhengdxumsft_3-1703575487692.pngvzhengdxumsft_4-1703575487693.png

Next, use the crossjoin function to create a new table.

The table contains the Cartesian product of all rows from all tables in the arguments

------------------------------------------------------------

Table 3 = CROSSJOIN('Table','Table 2')

------------------------------------------------------------

vzhengdxumsft_5-1703575497884.pngvzhengdxumsft_6-1703575497885.png

Create a measure to calculate the difference for the corresponding month:

------------------------------------------------------------

Measure = SUM('Table 3'[value])-SUM('Table 3'[Table_value])

------------------------------------------------------------

Then create a Matrix, Row is Month, Columns is Table_Month, Values is Measure:

vzhengdxumsft_7-1703575510803.png

 

Best Regards,

Zhengdong Xu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hello,

 

Thanks for the answer, that is want i want to achieve, but this solution is not suitable for huge dataset, because I have an error related to memory failure when I do the CROSSJOIN step. Do you know any other solution without this CROSSJOIN?

Ashish_Mathur
Super User
Super User

Hi,

Not clear with the business context of your requirement.  Why are you dragging Month/Year to the rows and columns?  What business question is getting answered by the differences which you want to see in the body of the matrix?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello Ashish,

 

Thanks for your answers. I edited the post with new information to clarify and answer your doubts

amitchandak
Super User
Super User

@Tasnalem , Create a date table and join the Date with that

 

You can create month on month measure like

 

example measures

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))


last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
Previous year Month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth(dateadd('Date'[Date],-11,MONTH)))
last year MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
Month behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Month))

 

 

Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

 

For Cohort Analysis, Customer Retention %- https://youtu.be/qY1SDF1cwsg

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.