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
siva_powerbi
Helper IV
Helper IV

Totals of Matrix visual in custom column at end of visual

I have generated a Matrix visual, total column is added at end of visual by default but I need the total to be a custom column not the auto generated one.

 

Since I am generating 2 saperate tables and making a union out of it, so I need totals of two tables saperately.

 

Input Data

DateAmount
03/01/20100
04/01/2050
05/01/2070
06/01/20150
07/01/20170
08/01/20120
09/01/2090
10/01/2080

 

Following formula I am using to generate columns:

 

Column 2 = SWITCH(TRUE(),
AND(Sheet2[Column1].[Date] >= DATE(2020,10,01) , Sheet2[Column1].[Date] < DATE(2020,11,01)),"Oct",
AND(Sheet2[Column1].[Date] >= DATE(2020,09,01) , Sheet2[Column1].[Date] < DATE(2020,10,01)),"Sep",
"Summary")  // Here I am inserting the new column summary for total of months (Sep, Oct)
 
Formual to generate the values
 
I tried two formulas one to generate the value of summary in else part as below (But this didn't work)
 
Column =
SWITCH(TRUE(),
AND(Sheet2[Column1].[Date] >= DATE(2020,10,01) , Sheet2[Column1].[Date] < DATE(2020,11,01)),Sheet2[Column2],
AND(Sheet2[Column1].[Date] >= DATE(2020,09,01) , Sheet2[Column1].[Date] < DATE(2020,10,01)),Sheet2[Column2],
CALCULATE(SUM(Sheet2[Column2]),(Sheet2[Column1].[Date] >= DATE(2020,10,01) && Sheet2[Column1].[Date] <
DATE(2020,11,01))))
Capture.PNG
 
 
 

Second Appraoch created a measure

 

Measure 2 = IF ( COUNTROWS ( DISTINCT ( Sheet2[Column 2]) ) = 1 , SUM ( Sheet2[Column2] ) ,
CALCULATE(SUMX(Sheet2, Sheet2[Column2]), Sheet2[Column 2] in {"Oct"}))
 
Visual
 
Capture1.PNG

 

 

 

Here  I am getting data in summary but its a wrong value, I need summary to be 170 instead of 660.

 

I am sure their should be a way.

 

Thanks in advance for help.

 

3 REPLIES 3
V-lianl-msft
Community Support
Community Support

Hi @siva_powerbi ,

 

Based on your description, the column2 you created does not meet your calculation requirements.

The summary field is at the same level as the month field, so the summary field does not calculate the sum of "OCT" and "SEP".

You need to use the all function to clear the filters in the table.

Try to create measure like this:

Measure = 
var summary = CALCULATE(SUM('Table'[Amount]),FILTER(ALL('Table'),'Table'[Column 2]in {"oct","sep"}))
var in_month = SUM('Table'[Amount])
return IF(MAX('Table'[Column 2])="summary",summary,in_month)

V-lianl-msft_0-1606890382779.png

 

 

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

@V-lianl-msft Thank you very much for the solution, its working.

Can you please help me with one more functionality.

In matrix visual that I have, their are rows that expand up to 5 levels, iwith your formual I am getting grand totals at all levels but I need the total to be changing as the level is expanded that is sum should be correct as the level is expanded or colapsed.

Can you please help me.

Thanks

amitchandak
Super User
Super User

@siva_powerbi , Not very clear on the approach, You can create measures with help from time intelligence and date table like 

 

//This month (Oct selected in slicer) and last month

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))
this month =MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH('Date'[Date])))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
previous month value =  CALCULATE(sum('Table'[total hours value]),previousmonth('Date'[Date]))

 

Rolling 2 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-2,MONTH))

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.