Forum Discussion
Calculate measure based on Filter selection
- 7 years ago
My suggestion would be to create two calculated tables from your DataTable representing North and South locations.
I named them 'North Filter' and 'South Filter'.
You can achieve this with:
North Filter = all('DataTable'[LocationId];'DataTable'[Location])
South Filter = all('DataTable'[LocationId];'DataTable'[Location])
I would than create for each calculated table, one inactive relationships with DataTable.
Calculated tables to be used as filters.
After that create the following measures:
Location Count=
COUNTROWS (
SUMMARIZE ( UNION ( 'North Filter', 'South Filter' ), [LocationId] )
)
This will give you all the distinct locations selected.
You can create also:
North Count=
CALCULATE ( COUNTROWS ( 'DataTable' ), USERELATIONSHIP ( 'DataTable'[LocationId], 'North Filter'[LocationId] ) )
This measure will count only the locations selected on the North Filter. I'm assuming that when nothing is selected the user wants ALL.
If you setup a table visual whith a filter on this last measure for only values greater than zero, you'll get the North information.
The same thing should be done for South.
Other measures created are:
North Female=
CALCULATE (
SUM ( 'DataTable'[Female] ),
USERELATIONSHIP ( 'DataTable'[LocationId], 'North Filter'[LocationId] )
)
North Male=
CALCULATE (
SUM ( 'DataTable'[Male] ),
USERELATIONSHIP ( 'DataTable'[LocationId], 'North Filter'[LocationId] )
)
South Female
CALCULATE (
SUM ( 'DataTable'[Female] ),
USERELATIONSHIP ( 'DataTable'[LocationId], 'South Filter'[LocationId] )
)
South Male=
CALCULATE (
SUM ( 'DataTable'[Male] ),
USERELATIONSHIP ( 'DataTable'[LocationId], 'South Filter'[LocationId] )
)Finaly, measures for the Totals are created:
Total Female = [North Female] + [South Female] Total Male = [North Male] + [South Male]
Final Result
Here is a link to the changes necessary for my suggestion: Sample Pbix