"dax switch"
12 TopicsHelp Adding Calculate Conditions to Switch Function
Need help adding correct calculations into my Switch function using two tables: 1) PPI (premium per phone interaction) table 2) PROD sales table Calculate "Total PPI" using this formula: Total Premium (from PROD Sales)/Total Count of PPI (from PPI) There is active relationship between "Date" and inactive between "Advisor" (not sure if I set it up correctly) I've included my PBI project with sample data and visuals to download/view: Power BI PPI Project Below my existing Switch statement; however I'm not getting correct results: Total PPI = SWITCH( TRUE(), //Case 1: When Advisor and Date selected HASONEFILTER('PROD SALES'[Advisor]) && HASONEFILTER('PROD SALES'[Date]), CALCULATE( DIVIDE([TotalPremium], [PPI Calls])), ), //Case 2: Only date selected HASONEVALUE('PROD SALES'[Date]), CALCULATE( DIVIDE ([TotalPremium],[PPI Calls]), USERELATIONSHIP('PROD SALES'[Date], 'PPI'[Date]) ), //Case 3: Only Advisor is selected HASONEVALUE('PROD SALES'[ADVISOR]), CALCULATE( DIVIDE ([TotalPremium],[PPI Calls]), USERELATIONSHIP('PROD SALES'[Advisor], 'PPI'[ADVISOR]) ), // Default: average over all call times if no or multiple selections DIVIDE([TotalPremium],[PPI Calls]) ) I need to add the following conditions to calculate PPI as well: - Selecting Department Only - Date + Department - Advisor + Date + Department My priority is when selecting a single date to show the correct PPI result. Total Premium selecting the date 5/15: $84,179.52 # PPI Calls from PPI Table for the selected date 5/15 = 142 Total Premium / PPI count = Total PPI Expected Total PPI result: $592.81 TOTAL PREMIUM FOR "Field" Department (from Prod Sales table): $846,573. 08 PPI Count FOR "Field" Department (from PPI table): 1,202 Total Premium / PPI count = Total PPI Expected Total PPI result when "Field" is selected: $704.30 Total Premium for "Call Center" Department (from Prod Sales table): $951,098.02 PPI Count for "Call Center" Department (from PPI table): 1,702 Total Premium/ PPI Count = Total PPI Expected Total PPI result when "Call Center" is selected: $558.81 Expected PPI when no filter is applied: $619.03 Appreciate your help!Solved718Views0likes2CommentsAdding Condition to Switch Measure to Output "0"
Hi! Need to add a condition to my Switch measure "Total Dynamic Calls" I want it to output "0" for SUM of [Total Calls] from the 'Combined Call Logs 5/17' table if the value "Field" from the UpdatedProd521 [Enrollment Type] table is selected in a slicer. Otherwise, it should output SUM Total Calls if the value "Call Center" is selected. Thanks in advance! Here is the current Switch measure: 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]) )Solved955Views0likes4CommentsAdding SWITCH for Average Call Time and Average Hold Time
Hi! I need help adding SWITCH function to two separate DAX measures for a Call Center that calculates "Average Call Time" and "Average Hold Time. There are inactive relationships between Advisor and Date from a Prod Sales Table and Combined Call Logs Table. Please use the same slicer conditions I used in a previous Total Calls measure: 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 is my DAX for average call time (without Switch) and outputs 0 if no 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 SecondsColumn VAR Minutes = INT (TotalSeconds / 60) VAR Seconds = MOD (TotalSeconds, 60) RETURN FORMAT (Minutes, "0") & " min" Here's my DAX for Average Hold Time (without Switch) and outputs 0 if no 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 SecondsColumn VAR Minutes = INT ( TotalSeconds / 60 ) VAR Seconds = MOD ( TotalSeconds, 60 ) RETURN FORMAT ( Minutes, "0" ) & " min, " & FORMAT ( Seconds, "0" ) & " sec"Solved692Views2likes2CommentsCalculated Column To Determine Attendance Status
I am building an attendance dashboard and already integrated holidays and weekends and a calculated column that calculated the durantion between the earliest entry and latest exit timestamps and everything checks out except for the "Attendance Status" calculated column where I am using the SWITCH function with all possible conditions but I am not getting the expected results as can be seen in the screenshot, when the day is "Regular" and the completed hours are equal or more than 8 then it should be fulfilled otherwise it is incomplete same with ramadan but the hours being 5 instead but I "Absent" and "Not Required" are the only results I am getting even when that is not the case. I tried to test out each condition individualy to troubleshoot but to no avail. Below is the dax expression I used: Attendance Status = SWITCH( TRUE(), ISBLANK([Completed_Hours]) && RELATED(Calendar[DayType]) IN {"Weekend", "Holiday"}, "Not Required", ISBLANK([Completed_Hours]) && RELATED(Calendar[DayType]) = "Regular", "Absent", ISBLANK([Completed_Hours]) && RELATED(Calendar[DayType]) = "Ramadan", "Absent", RELATED(Calendar[DayType]) = "Regular" && [Completed_Hours] >= 8, "Fulfilled", RELATED(Calendar[DayType]) = "Regular" && [Completed_Hours] < 8, "Incomplete", RELATED(Calendar[DayType]) = "Ramadan" && [Completed_Hours] >= 5, "Fulfilled", RELATED(Calendar[DayType]) = "Ramadan" && [Completed_Hours] < 5, "Incomplete", RELATED(Calendar[DayType]) IN {"Weekend", "Holiday"} && [Completed_Hours] >= 8, "Fulfilled", RELATED(Calendar[DayType]) IN {"Weekend", "Holiday"} && [Completed_Hours] < 8, "Incomplete", "Unknown" )Solved1KViews0likes5CommentsQuery Resources Issue - Actual vs Budget Finance Report
I am trying to construct a matrix that displays my details as rows, presenting five years of data that includes both actual values and budget figures. Specifically, I have five years of actual data and budget values only for the current year, along with calculations for variances between current year (CY) and last year (LY) actuals, as well as the growth from CY actual to LY actual and budget performance. However, I'm facing a challenge because I lack a dedicated column for these particulars; instead, the data is sourced from various MIS columns across three different tables, with inconsistent naming conventions. I can create the visual representation, but it breaks when I attempt to filter the months using a slicer.1.1KViews1like2CommentsNeed help with grouping a variable
I have a variable called program. The data in program conforms to the format year-program where year can equal any year in the format yyyy, and program can be either 01, 04, 06, 09, 12. For example 2019-01, 2019-04, 2020-01, 2020-04, 2020-06. I would like to create a new measure called 'program-grouped', where any program ending in '01' is called January, any program ending in '04' is called April, and any program ending in '06' is called June. I tried the following but it did not work. Any ideas? Program-Grouped = SWITCH( TRUE(), RIGHT([program], 2) = "01", "January", RIGHT([program], 2) = "04", "April", RIGHT([program], 2) = "06", "June", "Other" )Solved1.2KViews0likes5CommentsHow to Capture Changes by Specific Filters
Hello I am fairly new to PowerBI and not sure if this is something I can do but I have a visual that I need to get the Net change by Month and Country. I have provided a photo below with the current visual. The goal is to create a new measure or column that would be able to show me either the sum of the values in the red or show the difference between the Starting Headcount and the Ending Headcount. The issue I am having is those values under USA and IND are values of column Roll on/ Roll Off and I am having trouble trying to distinguish them, I have tried using the Switch function but no success. Could anyone help point me in the right direction? Thank you.389Views0likes1CommentPowerBI Preset date selection and custom selection with comparison period
Hello, We are trying to make a preset date list that compares the same time period last year, whilst also having the option to use a custom filter with the ability to also use a custom comparison date. For some context we have set up the preset date list and have added a dax calcualtion to show the same time period for the previous year i.e. it will show 01/05/2024 compared to 01/05/2023. However, we can not then get a custom date selection with the option to use an additional calendar for a comparison. We've found loads of videos showing how to do this for a single date, but not including a comparison date. Any help would be hugely appreciated! Thanks in Advance! DataContet835Views0likes2CommentsSwitch color hierarchy <- Is it possible?
Hi! I made this code that will change colors on my dashboard depending whether the value in question is negative or positive, but I did also want to have a third color(orange), which would signify that the value is not to far off neagative: Bounce Rate Color Leaflet BE = SWITCH( TRUE(), [Bounce Rate (Up to Current Month) Leaflet BE] > [Bounce Rate Leaflet BE], "#00FF00", --green [Bounce Rate (Up to Current Month) Leaflet BE] < [Bounce Rate Leaflet BE], "#FF0000", AND([Bounce Rate Dif Current year and past year Leaflet BE] >= 0.01, [Bounce Rate Dif Current year and past year Leaflet BE] <= 1), "#FFA500", --orange "#000000" ) but of course the orange won't work since there is no hierarchy amongst the different sections of the coding, so the green and the red always override the orange. With this in mind, what would be the best solution to introducing this third color? Thank you very much for your time.Solved718Views0likes2CommentsCalling a semaphore measure in a new measure ; switch/ifcode
Hello all, I have a measure that calculates semaphore value based on Target column and Value column, but it works on single filter selection. Now i want to create a new measure that will call upon semaphore one and do next logic: If ,for two selected KPI (semaphore values), one is green and other is yellow or black ,then display green sempahore otherwise red one.. I've tried muliple things but each time it only works for single selection of filter....probably because of SELECTEDVALUE function. Any help suggestion is welcomed! Semaphore measure: Semaphores NEW 2024 YTD = VAR CurrentMonth = MONTH(TODAY()) VAR JanToCurrentMonthVALUE = CALCULATE( SUM('Actual_2024'[Value]), FILTER( 'Actual_2024', 'Actual_2024'[Month] >= 1 && 'Actual_2024'[Month] <= 12 ),'Actual_2024'[Month] <= CurrentMonth ) var notisblank = CALCULATE(COUNTROWS('Actual_2024'),FILTER(Actual_2024,Actual_2024[Month]>= 1 && Actual_2024[Month]<= 12), NOT(ISBLANK('Actual_2024'[Value]))) var JanToCurrentMonth = DIVIDE(JanToCurrentMonthVALUE,notisblank) // VAR JanToCurrentMonthTArget = CALCULATE( // SUM('Targets_2024'[Target]), // FILTER( // 'Targets_2024', // 'Targets_2024'[Month] >= 1 && 'Targets_2024'[Month] <= 12 // ),'Targets_2024'[Month] <= CurrentMonth-1 // ) // var Target = // DIVIDE(JanToCurrentMonthTArget,notisblank) var TargetX =CALCULATE(CALCULATE(SUM(Targets_2024[Target]),Targets_2024[Month]= 2024)) VAR FourPercentage = TargetX / 20 VAR FourPercentageAbs = ABS(FourPercentage) RETURN IF( SELECTEDVALUE('CpC KPIs_2024'[Semaphore]) = "G" , IF(ISBLANK(JanToCurrentMonth) , "⚫" /*"#808080"*/ , IF(ISBLANK(TargetX) , "⚫" /*"#808080"*/ , IF(JanToCurrentMonth >= TargetX , "🟢" /* "#67BB06" */ , /* green */ IF((JanToCurrentMonth-TargetX)* -1 <= FourPercentage , "🟡" /*"#fffb00"*/ ,/* yellow */ "🔴" /* "#F00202" */ /* red */ )) )), /* RED ABOVE TARGET */ IF( SELECTEDVALUE('CpC KPIs_2024'[Semaphore]) = "R" , IF(ISBLANK(JanToCurrentMonth) , "⚫" /*"#808080"*/ , IF(ISBLANK(TargetX) , "⚫" /*"#808080"*/ , IF(JanToCurrentMonth <= TargetX , "🟢" /* "#67BB06" */ /* green */ , IF((JanToCurrentMonth-TargetX) <= FourPercentage ,"🟡" /* "#fffb00" */ ,/* yellow */ "🔴" /* "#F00202" */ /* red */ )) )),"⚪")) __________________613Views0likes1Comment