Forum Discussion
sboinala
6 years agoRegular Visitor
Count values
I have two tables Customers a b c d e f Account Type: Customer Fuel a Gas a Elec b Gas c Gas c Elec d Gas d Elec e Elec e Elec ...
- 6 years ago
Hi,
Please try these three measures first:
Gas & Elec Counts = SUMX ( DISTINCT ( Customer[Customers] ), CALCULATE ( IF ( CALCULATE ( DISTINCTCOUNT ( 'Account Type'[Customer&Fuel] ), FILTER ( ALLSELECTED ( 'Account Type' ), 'Account Type'[Customer] IN FILTERS ( Customer[Customers] ) ) ) > 1, 1, 0 ) ) )Gas Only Count = SUMX ( DISTINCT ( Customer[Customers] ), CALCULATE ( IF ( CALCULATE ( DISTINCTCOUNT ( 'Account Type'[Customer&Fuel] ), FILTER ( ALLSELECTED ( 'Account Type' ), 'Account Type'[Customer] IN FILTERS ( Customer[Customers] ) ) ) = 1 && CALCULATE ( MAX ( 'Account Type'[Fuel] ), FILTER ( ALLSELECTED ( 'Account Type' ), 'Account Type'[Customer] IN FILTERS ( Customer[Customers] ) ) ) = "Gas", 1, 0 ) ) )Elec Only Count = SUMX ( DISTINCT ( Customer[Customers] ), CALCULATE ( IF ( CALCULATE ( DISTINCTCOUNT ( 'Account Type'[Customer&Fuel] ), FILTER ( ALLSELECTED ( 'Account Type' ), 'Account Type'[Customer] IN FILTERS ( Customer[Customers] ) ) ) = 1 && CALCULATE ( MAX ( 'Account Type'[Fuel] ), FILTER ( ALLSELECTED ( 'Account Type' ), 'Account Type'[Customer] IN FILTERS ( Customer[Customers] ) ) ) = "Elec", 1, 0 ) ) )Then create a slicer table by Enter Data:
Then try this count measure:
Count = SUMX ( DISTINCT ( 'Slicer Table'[Category] ), CALCULATE ( SWITCH ( MAX ( 'Slicer Table'[Category] ), "Elec Counts", [Elec Only Count], "Gas Counts", [Gas Only Count], "Gas & Elec Counts", [Gas & Elec Counts] ) ) )The result shows:
Here is my test pbix file:
Hope this helps.
Best Regards,
Giotto Zhi
v-gizhi-msft
Community Support
6 years agoHi,
Please try these three measures first:
Gas & Elec Counts =
SUMX (
DISTINCT ( Customer[Customers] ),
CALCULATE (
IF (
CALCULATE (
DISTINCTCOUNT ( 'Account Type'[Customer&Fuel] ),
FILTER (
ALLSELECTED ( 'Account Type' ),
'Account Type'[Customer] IN FILTERS ( Customer[Customers] )
)
) > 1,
1,
0
)
)
)Gas Only Count =
SUMX (
DISTINCT ( Customer[Customers] ),
CALCULATE (
IF (
CALCULATE (
DISTINCTCOUNT ( 'Account Type'[Customer&Fuel] ),
FILTER (
ALLSELECTED ( 'Account Type' ),
'Account Type'[Customer] IN FILTERS ( Customer[Customers] )
)
) = 1
&& CALCULATE (
MAX ( 'Account Type'[Fuel] ),
FILTER (
ALLSELECTED ( 'Account Type' ),
'Account Type'[Customer] IN FILTERS ( Customer[Customers] )
)
) = "Gas",
1,
0
)
)
)Elec Only Count =
SUMX (
DISTINCT ( Customer[Customers] ),
CALCULATE (
IF (
CALCULATE (
DISTINCTCOUNT ( 'Account Type'[Customer&Fuel] ),
FILTER (
ALLSELECTED ( 'Account Type' ),
'Account Type'[Customer] IN FILTERS ( Customer[Customers] )
)
) = 1
&& CALCULATE (
MAX ( 'Account Type'[Fuel] ),
FILTER (
ALLSELECTED ( 'Account Type' ),
'Account Type'[Customer] IN FILTERS ( Customer[Customers] )
)
) = "Elec",
1,
0
)
)
)Then create a slicer table by Enter Data:
Then try this count measure:
Count =
SUMX (
DISTINCT ( 'Slicer Table'[Category] ),
CALCULATE (
SWITCH (
MAX ( 'Slicer Table'[Category] ),
"Elec Counts", [Elec Only Count],
"Gas Counts", [Gas Only Count],
"Gas & Elec Counts", [Gas & Elec Counts]
)
)
)The result shows:
Here is my test pbix file:
Hope this helps.
Best Regards,
Giotto Zhi