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
sahgir123
Frequent Visitor

Creating Matrix Visual with Cumulative Sum and Ratio Calculation

I have 2 table

Sales DateComplaint DateDatezdiffProducttotal value
Jan-24Jan-240A2
Jan-24Feb-241A3
Mar-23Jun-233A3
Apr-23Oct-236A4
May-23Feb-249A5
Jun-23Jun-2412A6
Jan-23Jan-230A7
Jan-23Apr-233A8
Jan-24Mar-242A2
Jan-24Apr-243A1
Jan-24May-244A2
Jan-24Jun-245A5
Jan-24Jul-246A2
Jan-24Aug-247A2
Jan-24Sep-248A4
Jan-24Oct-249A1
Jul-23Apr-249A3
Oct-23Apr-246A 

 

and second table contain sales value monthly basis

Sale DateTotal Sale
Jan-2423
Feb-2434
Oct-2346
Mar-2423
Jul-2350

and Output table i want like this 

Output    
Complaint DateApr-24
Datediff 369
ProductA81627

 and

Complaint DateApr-24
Datediff 369
ProductA0.3478260.3478260.54


I want a result in same way in matrix visual. in value i have used cumulative sum of total value.
for eg. if complaint date is april 24 and datediff is 3 then complaint date go back 3 month, so it will start with Complaint Jan 24 , similarly if complaint date is April 24 and datediff is 6 so it will go back 6 month so month will start with Oct 23 - April 24 and same logic for 9 datediff value.
and also want one more calculation which show ratio, for eg if cpmplaint date is April 24 and datediff is 3 then result should be  8/23 ---cumulative total value / total sales(from sale table) , second example if complaint date is April 24 and datediff is 6 then result will be 16/ 46 - (46 is value for oct23 sale date from second table) why 46 becuase complaint date is April 24 and datediff we are using 6 so it will go 6 month before, so sale month will be Oct23. similary for 9 so it will 27/50.

Request for Assistance:

I'm struggling to implement this logic in Power BI to create the desired matrix visual. Could someone please guide me on how to achieve this? Any suggestions, DAX calculations, or Power BI techniques would be greatly appreciated!

Thank you in advance for your help!

Best regards,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sahgir123 ,

The Table data is shown below:

'Table'

vzhouwenmsft_0-1717396928394.png

'Table2'

vzhouwenmsft_1-1717396949073.png

Please follow these steps:
1. Use the following DAX expression to create columns in 'Table'

Sales_Date = 
VAR _a = RIGHT([Sales Date],3)
VAR _b = VALUE(LEFT([Sales Date],2))
VAR _c = SWITCH(TRUE(),
_a = "Jan",1,
_a = "Feb",2,
_a = "Mar",3,
_a = "Apr",4,
_a = "May",5,
_a = "Jun",6,
_a = "Jul",7,
_a = "Aug",8,
_a = "Sep",9,
_a = "Oct",10,
_a = "Nov",11,
_a = "Dec",12
)
RETURN  _b * 100 + _c
Complaint_Date = 
VAR _a = RIGHT([Complaint Date],3)
VAR _b = VALUE(LEFT([Complaint Date],2))
VAR _c = SWITCH(TRUE(),
_a = "Jan",1,
_a = "Feb",2,
_a = "Mar",3,
_a = "Apr",4,
_a = "May",5,
_a = "Jun",6,
_a = "Jul",7,
_a = "Aug",8,
_a = "Sep",9,
_a = "Oct",10,
_a = "Nov",11,
_a = "Dec",12
)
RETURN  _b * 100 + _c

vzhouwenmsft_2-1717397274603.png

2.Use the following DAX expression to create a table

Table3 = 
VAR _24_Apr = SELECTCOLUMNS(FILTER('Table','Table'[Complaint Date] = "24-Apr"),"Complaint Date",[Complaint Date],"Datezadiff",[Datezdiff])
VAR _24_Jan = SELECTCOLUMNS(FILTER('Table','Table'[Complaint Date] = "24-Jan"),"Complaint Date",[Complaint Date],"Datezadiff",[Datezdiff])
VAR _24_Feb = SELECTCOLUMNS(FILTER('Table','Table'[Complaint Date] = "24-Feb"),"Complaint Date",[Complaint Date],"Datezadiff",[Datezdiff])
RETURN UNION(_24_Jan,_24_Feb,_24_Apr)

3.Use the following DAX expression to create columns in 'Table3'

24-Jan = IF([Complaint Date] = "24-Jan",[Datezadiff]) 
24-Apr = IF([Complaint Date] = "24-Apr",[Datezadiff]) 

vzhouwenmsft_3-1717397454431.png

4.Use the following DAX expression to create  measures

Total = 
var _a = SWITCH(TRUE(),
ISFILTERED('Table3'[24-Apr]),"24-Apr",
ISFILTERED('Table3'[24-Jan]),"24-Jan")  
VAR _b = SELECTEDVALUE('Table3'[Datezadiff])
VAR _c = MAXX(FILTER('Table','Table'[Complaint Date] = _a),[Complaint_Date])
VAR _d = MAXX(FILTER('Table','Table'[Complaint Date] = _a && 'Table'[Datezdiff] = _b),[Sales_Date])
VAR _e = SUMX(FILTER('Table','Table'[Complaint_Date] <= _c && 'Table'[Sales_Date] >= _d ),[total value]) //It is used to calculate the total value, and the judgment condition can be modified according to your requirements.
VAR _f = IF(ISBLANK(SELECTEDVALUE('Table3'[Datezadiff])),BLANK(),_e)
RETURN _f
% = 
var _a = SWITCH(TRUE(),
ISFILTERED('Table3'[24-Apr]),"24-Apr",
ISFILTERED('Table3'[24-Jan]),"24-Jan")  
VAR _b = SELECTEDVALUE('Table3'[Datezadiff])
VAR _c = MAXX(FILTER('Table','Table'[Complaint Date] = _a),[Complaint_Date])
VAR _d = MAXX(FILTER('Table','Table'[Complaint Date] = _a && 'Table'[Datezdiff] = _b),[Sales_Date])
VAR _e = MAXX(FILTER('Table','Table'[Sales_Date] = _d),[Sales Date])
RETURN DIVIDE([Measure],LOOKUPVALUE(Table2[Total Sale],Table2[Sale Date],_e))

5.Final output

vzhouwenmsft_4-1717397688371.png

 

vzhouwenmsft_5-1717397705999.png

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @sahgir123 ,

The Table data is shown below:

'Table'

vzhouwenmsft_0-1717396928394.png

'Table2'

vzhouwenmsft_1-1717396949073.png

Please follow these steps:
1. Use the following DAX expression to create columns in 'Table'

Sales_Date = 
VAR _a = RIGHT([Sales Date],3)
VAR _b = VALUE(LEFT([Sales Date],2))
VAR _c = SWITCH(TRUE(),
_a = "Jan",1,
_a = "Feb",2,
_a = "Mar",3,
_a = "Apr",4,
_a = "May",5,
_a = "Jun",6,
_a = "Jul",7,
_a = "Aug",8,
_a = "Sep",9,
_a = "Oct",10,
_a = "Nov",11,
_a = "Dec",12
)
RETURN  _b * 100 + _c
Complaint_Date = 
VAR _a = RIGHT([Complaint Date],3)
VAR _b = VALUE(LEFT([Complaint Date],2))
VAR _c = SWITCH(TRUE(),
_a = "Jan",1,
_a = "Feb",2,
_a = "Mar",3,
_a = "Apr",4,
_a = "May",5,
_a = "Jun",6,
_a = "Jul",7,
_a = "Aug",8,
_a = "Sep",9,
_a = "Oct",10,
_a = "Nov",11,
_a = "Dec",12
)
RETURN  _b * 100 + _c

vzhouwenmsft_2-1717397274603.png

2.Use the following DAX expression to create a table

Table3 = 
VAR _24_Apr = SELECTCOLUMNS(FILTER('Table','Table'[Complaint Date] = "24-Apr"),"Complaint Date",[Complaint Date],"Datezadiff",[Datezdiff])
VAR _24_Jan = SELECTCOLUMNS(FILTER('Table','Table'[Complaint Date] = "24-Jan"),"Complaint Date",[Complaint Date],"Datezadiff",[Datezdiff])
VAR _24_Feb = SELECTCOLUMNS(FILTER('Table','Table'[Complaint Date] = "24-Feb"),"Complaint Date",[Complaint Date],"Datezadiff",[Datezdiff])
RETURN UNION(_24_Jan,_24_Feb,_24_Apr)

3.Use the following DAX expression to create columns in 'Table3'

24-Jan = IF([Complaint Date] = "24-Jan",[Datezadiff]) 
24-Apr = IF([Complaint Date] = "24-Apr",[Datezadiff]) 

vzhouwenmsft_3-1717397454431.png

4.Use the following DAX expression to create  measures

Total = 
var _a = SWITCH(TRUE(),
ISFILTERED('Table3'[24-Apr]),"24-Apr",
ISFILTERED('Table3'[24-Jan]),"24-Jan")  
VAR _b = SELECTEDVALUE('Table3'[Datezadiff])
VAR _c = MAXX(FILTER('Table','Table'[Complaint Date] = _a),[Complaint_Date])
VAR _d = MAXX(FILTER('Table','Table'[Complaint Date] = _a && 'Table'[Datezdiff] = _b),[Sales_Date])
VAR _e = SUMX(FILTER('Table','Table'[Complaint_Date] <= _c && 'Table'[Sales_Date] >= _d ),[total value]) //It is used to calculate the total value, and the judgment condition can be modified according to your requirements.
VAR _f = IF(ISBLANK(SELECTEDVALUE('Table3'[Datezadiff])),BLANK(),_e)
RETURN _f
% = 
var _a = SWITCH(TRUE(),
ISFILTERED('Table3'[24-Apr]),"24-Apr",
ISFILTERED('Table3'[24-Jan]),"24-Jan")  
VAR _b = SELECTEDVALUE('Table3'[Datezadiff])
VAR _c = MAXX(FILTER('Table','Table'[Complaint Date] = _a),[Complaint_Date])
VAR _d = MAXX(FILTER('Table','Table'[Complaint Date] = _a && 'Table'[Datezdiff] = _b),[Sales_Date])
VAR _e = MAXX(FILTER('Table','Table'[Sales_Date] = _d),[Sales Date])
RETURN DIVIDE([Measure],LOOKUPVALUE(Table2[Total Sale],Table2[Sale Date],_e))

5.Final output

vzhouwenmsft_4-1717397688371.png

 

vzhouwenmsft_5-1717397705999.png

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

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