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

Summing and Slicing multiple columns

Hello,

 

I've been given some data to build a report and part of it involves summarizing some data across multiple columns. Example:

 

IncidentRoot Cause 1Root Cause 2Root Cause 3Root Cause 4
1HumanSystem  
2Human   
3HumanProcess  
4HumanProcess  
5Process   
6System   
7HumanProcessSystem 
8External   
9HumanSystem  
10HumanProcess  

 

I created a Slicer table using:

 

SlicerTable = 
Distinct(
    UNION(
        VALUES('Table'[Root Cause 1]),
        VALUES('Table'[Root Cause 2]),
        VALUES('Table'[Root Cause 3]),
        VALUES('Table'[Root Cause 4])
    )
)

 

And a measure:

 

RootSlicer = 
If(
    MIN('Table'[Root Cause 1]) in VALUES(SlicerTable[RootCauseSlicer])
    || MIN('Table'[Root Cause 2]) in VALUES(SlicerTable[RootCauseSlicer])
    || MIN('Table'[Root Cause 3]) in VALUES(SlicerTable[RootCauseSlicer])
    || MIN('Table'[Root Cause 4]) in VALUES(SlicerTable[RootCauseSlicer]),
    1,
    blank()
    )

 

This works for filtering the table visual:

GBKYE2_1-1650911876157.png

As you can see the "Count of incident" is 10 but I would like it to count the matching results and return "4" as the total. I would also like to build visuals/charts with some other columns in the original data such as breakdown by Team so is there any way to work around that?

 

Any suggestions would be greatly appreciated, thanks!

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@GBKYE2 don't change to 0 🙂
Try this:

RootSlicer = 
VAR _slicer_values = VALUES(SlicerTable[RootCauseSlicer])
VAR _result = 
SUMX(
	'Table',
	If(
	    'Table'[Root Cause 1] in _slicer_values
	    || 'Table'[Root Cause 2] in _slicer_values
	    || 'Table'[Root Cause 3] in _slicer_values
	    || 'Table'[Root Cause 4] in _slicer_values,
	    1,
	    blank()
    )
)
RETURN
	_result


or this:

RootSlicer = 
VAR _slicer_values = VALUES(SlicerTable[RootCauseSlicer])
VAR _result = 
SUMX(
	SUMMARIZE(
		'Table'
		'Table'[Incident],
		'Table'[Root Cause 1],
		'Table'[Root Cause 2],
		'Table'[Root Cause 3],
		'Table'[Root Cause 4]
	),
	If(
	    MIN('Table'[Root Cause 1]) in _slicer_values
	    || MIN('Table'[Root Cause 2]) in _slicer_values
	    || MIN('Table'[Root Cause 3]) in _slicer_values
	    || MIN('Table'[Root Cause 4]) in _slicer_values,
	    1,
	    blank()
    )
)

View solution in original post

4 REPLIES 4
SpartaBI
Community Champion
Community Champion

@GBKYE2 try this: (I also created a VAR for the slicer values as a best practice for performance and readabilty. Perfornance wise probably not relevant in the size of your data, but good getting used to use VARs where possible):

RootSlicer = 
VAR _slicer_values = VALUES(SlicerTable[RootCauseSlicer])
VAR _result = 
SUMX(
	VALUES('Table'[Incident]),
	If(
	    MIN('Table'[Root Cause 1]) in _slicer_values
	    || MIN('Table'[Root Cause 2]) in _slicer_values
	    || MIN('Table'[Root Cause 3]) in _slicer_values
	    || MIN('Table'[Root Cause 4]) in _slicer_values,
	    1,
	    blank()
    )
)
RETURN
	_result

 

@SpartaBI Thanks for the input and the tip about VARs, I will keep that in mind in future!

 

I think I understand what that DAX is supposed to do, but when I implemented it I ran into some issues:

GBKYE2_0-1650965410000.png

I thought this might be caused by the use of blank() so I tried replacing it with 0 for the purpose of the SumX but then this happens:

GBKYE2_0-1650974350821.png

I can fix the table with a visual level filter with "Rootslicer = 1" but there's still some issues with the actual summations:

GBKYE2_1-1650965877357.png

Any ideas what causes this? Thanks!

SpartaBI
Community Champion
Community Champion

@GBKYE2 don't change to 0 🙂
Try this:

RootSlicer = 
VAR _slicer_values = VALUES(SlicerTable[RootCauseSlicer])
VAR _result = 
SUMX(
	'Table',
	If(
	    'Table'[Root Cause 1] in _slicer_values
	    || 'Table'[Root Cause 2] in _slicer_values
	    || 'Table'[Root Cause 3] in _slicer_values
	    || 'Table'[Root Cause 4] in _slicer_values,
	    1,
	    blank()
    )
)
RETURN
	_result


or this:

RootSlicer = 
VAR _slicer_values = VALUES(SlicerTable[RootCauseSlicer])
VAR _result = 
SUMX(
	SUMMARIZE(
		'Table'
		'Table'[Incident],
		'Table'[Root Cause 1],
		'Table'[Root Cause 2],
		'Table'[Root Cause 3],
		'Table'[Root Cause 4]
	),
	If(
	    MIN('Table'[Root Cause 1]) in _slicer_values
	    || MIN('Table'[Root Cause 2]) in _slicer_values
	    || MIN('Table'[Root Cause 3]) in _slicer_values
	    || MIN('Table'[Root Cause 4]) in _slicer_values,
	    1,
	    blank()
    )
)

Perfect! Thank you!

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.