Forum Discussion
Adding Condition to SWITCH function for Call Center
- 1 year ago
Hi jabueg ,
Thanks for reaching out to the Microsoft Fabric Community.
To achieve the requirement of calculating total calls based on Advisor and Date selections from the UpdatedProd521 table, I tested the scenario using a sample dataset with inactive relationships between the tables. Here’s the DAX measure that produces the expected result when either or both filters are applied:
Total Calls Dynamic = SWITCH( TRUE(), // Case 1: Single Advisor AND Single Date selected HASONEVALUE(UpdatedProd521[Advisor]) && HASONEVALUE(UpdatedProd521[Date]), CALCULATE( SUM('Combined Call Logs 5/17'[CALLS]), USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR]), FILTER( 'Combined Call Logs 5/17', 'Combined Call Logs 5/17'[DATE] = VALUES(UpdatedProd521[Date]) ) ), // Case 2: Only Advisor is selected HASONEVALUE(UpdatedProd521[Advisor]), CALCULATE( SUM('Combined Call Logs 5/17'[CALLS]), USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR]) ), // Case 3: Only Date is selected HASONEVALUE(UpdatedProd521[Date]), CALCULATE( SUM('Combined Call Logs 5/17'[CALLS]), USERELATIONSHIP('Combined Call Logs 5/17'[DATE], UpdatedProd521[Date]) ), // Default: sum all calls if no or multiple selections SUM('Combined Call Logs 5/17'[CALLS]) )Here are some screenshots for reference:
Also thanks to DataNinja777 and Jai-Rathinavel for their insights and suggestions.
Attaching a PBIX file with the sample data and measure for testing.
Hope this helps. Please reach out for further assistance.
If this post helps, then please consider giving it a kudos and accepting it as the solution to help other members find it more quickly.Thank you.
Hi jabueg ,
Thanks for reaching out to the Microsoft Fabric Community.
To achieve the requirement of calculating total calls based on Advisor and Date selections from the UpdatedProd521 table, I tested the scenario using a sample dataset with inactive relationships between the tables. Here’s the DAX measure that produces the expected result when either or both filters are applied:
Total Calls Dynamic =
SWITCH(
TRUE(),
// Case 1: Single Advisor AND Single Date selected
HASONEVALUE(UpdatedProd521[Advisor]) &&
HASONEVALUE(UpdatedProd521[Date]),
CALCULATE(
SUM('Combined Call Logs 5/17'[CALLS]),
USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR]),
FILTER(
'Combined Call Logs 5/17',
'Combined Call Logs 5/17'[DATE] = VALUES(UpdatedProd521[Date])
)
),
// Case 2: Only Advisor is selected
HASONEVALUE(UpdatedProd521[Advisor]),
CALCULATE(
SUM('Combined Call Logs 5/17'[CALLS]),
USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR])
),
// Case 3: Only Date is selected
HASONEVALUE(UpdatedProd521[Date]),
CALCULATE(
SUM('Combined Call Logs 5/17'[CALLS]),
USERELATIONSHIP('Combined Call Logs 5/17'[DATE], UpdatedProd521[Date])
),
// Default: sum all calls if no or multiple selections
SUM('Combined Call Logs 5/17'[CALLS])
)
Here are some screenshots for reference:
Also thanks to DataNinja777 and Jai-Rathinavel for their insights and suggestions.
Attaching a PBIX file with the sample data and measure for testing.
Hope this helps. Please reach out for further assistance.
If this post helps, then please consider giving it a kudos and accepting it as the solution to help other members find it more quickly.
Thank you.
- jabueg1 year agoHelper I
Thank you v-veshwara-msft This worked beautifully, and now I can see total calls for single dates and single advisor.
I do need another Switch for an "Average Call Time" and "Average Hold Time" measures using the same inactive relationships and same type of conditions as the "Total Calls Dynamic" that you solved. Can you help with that as well?Here is my current DAX for Average Call Time:
AverageCallDuration =VAR TotalSeconds =COALESCE(CALCULATE(AVERAGE('Combined Call Logs 5/17'[CALL TIME (SEC)]),USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR])),0) //Replace YourTable and SecondsColumnVAR Minutes =INT (TotalSeconds / 60)VAR Seconds =MOD (TotalSeconds, 60)RETURNFORMAT (Minutes, "0") & " min"Average Hold Time:
Avg Hold Time =VAR TotalSeconds =COALESCE(CALCULATE(AVERAGE('Combined Call Logs 5/17'[HOLD TIME (SEC)]),USERELATIONSHIP('UpdatedProd521'[Advisor], 'Combined Call Logs 5/17'[ADVISOR])),0) // Replace YourTable and SecondsColumnVAR Minutes =INT ( TotalSeconds / 60 )VAR Seconds =MOD ( TotalSeconds, 60 )RETURNFORMAT ( Minutes, "0" ) & " min, " & FORMAT ( Seconds, "0" ) & " sec"