"switch"
9 TopicsCount new value as a single frequency, instead of twice, in the same DAX formula
I have a table (actions_taken) with columns called project_number, action_effective_dt, and action_name. All these values can and do repeat. Each project number can repeat & have multiple action names associated with it & multiple action effective dates. One of you helped me write the DAX formula below (thank you!), but I now want to modify this formula to count the “IE/FE” as a single occurrence. Currently the “IE/FE” is being double counted. DAX Formula: ClosingsAction = VAR CurrentProject = actions_taken[project_number] VAR CurrentDate = actions_taken[action_effective_dt] VAR HasA = CALCULATE( COUNTROWS(actions_taken), ALL(actions_taken), -- Overrides context transition to scan the whole table actions_taken[project_number] = CurrentProject, actions_taken[action_effective_dt] = CurrentDate, actions_taken[action_name] = " Initially Endorsed" ) > 0 VAR HasB = CALCULATE( COUNTROWS(actions_taken), ALL(actions_taken), -- Overrides context transition to scan the whole table actions_taken[project_number] = CurrentProject, actions_taken[action_effective_dt] = CurrentDate, actions_taken[action_name] = "Finally Endorsed" ) > 0 RETURN SWITCH( TRUE(), -- If both A and B exist on same date for the same project actions_taken[action_name] IN {"Initially Endorsed","Finally Endorsed"} && HasA && HasB, "IE/FE", -- Individual mappings actions_taken[action_name] = "Initially Endorsed", "IE", actions_taken[action_name] = "Finally Endorsed", "FE", actions_taken[action_name] = "Firm Application Withdrawn", "W", actions_taken[action_name] = "Firm Commitment Expired", "E", BLANK() ) Sample data: Project_number Action_effective_dt Action_name Ghj123 5/20/2026 Initially Endorsed Ghj123 5/20/2026 Finally Endorsed Hop963 4/8/2026 Firm Commitment Expired Lty789 3/7/2026 Firm Application Withdrawn Dsw493 3/7/2026 Firm Commitment Expired Kjh259 3/5/2026 Initially Endorsed Table outcomes with reclassified categories from “ClosingsAction” column: Action_Name Frequency IE/FE 2 (I want this to be counted as a single action/ occurrence) E 2 W 1 IE 1Solved1.4KViews0likes8CommentsAdding 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"Solved693Views2likes2CommentsAdding Condition to SWITCH function for Call Center
Hi! I have a measure that calculates Total Calls, depending if an Advisor or Date is selected in a slicer. It will calculate SUM of Total Calls using an inactive relationship between the two tables. UpdatedProd521 = sales table Combined Call Logs 5/17 = call logs table Inactive relationships between [Date] And [Advisor] columns I need help to add a new argument that outputs SUM total from the Updated Call Logs 5/17[Calls] column if a single Advisor AND single Date are selected using the relationships between the two tables. Here is the syntax I used that currently works if either Advisor or Date are selected: Total Calls Dynamic = SWITCH( HASONEVALUE(UpdatedProd521[Advisor]),TRUE(), CALCULATE( SUM('Combined Call Logs 5/17'[CALLS]),USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR]) //When an advisor is selected ) ,NOT HASONEVALUE(UpdatedProd521[Advisor]) && (NOT ISBLANK(MAX('UpdatedProd521'[Date]) || NOT ISBLANK(MAX('Combined Call Logs 5/17'[DATE])))),TRUE(), CALCULATE(SUM('Combined Call Logs 5/17'[CALLS]), USERELATIONSHIP('Combined Call Logs 5/17'[DATE], UpdatedProd521[Date]) //When date is selected )Solved1.4KViews0likes6CommentsCalculated 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" )Solved1KViews0likes5CommentsSwitch 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.Solved720Views0likes2CommentsUsing a switch statement to select a column
I am completely stumped. I'm trying to use… a slicer to select a single value (this works) Then use that value with a SWITCH statement to select a column (this doesn't work) How I've set this up... I have a table called 'Slicer_Table' This table has one column called 'Slicer_Options' The column contains two twos and two values 1 & 2. I have a second table called 'Data_Table'. This table has two columns, called 'Column_1' and 'Column_2'. 'Column_1' contains the values A, B, C, D, E, F, G 'Column_2' contains the values H, I, J, K, L, M, N In the dashboard I have a slicer. Which uses 'Slicer_Table->Slicer_Options' as it's field value. It has the style Tile & has the selection 'Single Select' 'On'. In the dashboard I have a measure called 'Select_Column' Associated with the 'Data_Table'. This measure (doesn't) work by… Taking the currently selected slicer value, and storing it in the VAR SelectedColumn e.g., VAR SelectedColumn = SELECTEDVALUE(Slicer_Table[Slicer_Options]) Using 'SelectedColumn' in a SWITCH statement to return Data_Table[Column_1] or Data_Table[Column_2] Depending on the value of 'SelectedColumn' e.g., SWITCH( SelectedColumn, 1, Data_Table[Column_1], 2, Data_Table[Column_2] ) The measure as a whole looks like: Select_Column = VAR SelectedColumn = SELECTEDVALUE(Slicer_Table[Slicer_Options]) RETURN SWITCH( SelectedColumn, 1, Data_Table[Column_1], 2, Data_Table[Column_2] ) However, this doesn't work. No matter what the value of 'SelectedColumn' Nothing is returned by the SWITCH statement. If I replace 'SelectedColumn' with a constant value e.g., Select_Column = VAR SelectedColumn = SELECTEDVALUE(Slicer_Table[Slicer_Options]) RETURN SWITCH( 1, 1, Data_Table[Column_1], 2, Data_Table[Column_2] ) Then it does work - Setting the value to 1 returns Data_Table[Column_1] Setting the value to 2 returns Data_Table[Column_2] as I would expect. That it works with constant values, makes me think this should be feasible with a variable value. & that I am doing something wrong - I'm just not sure what?Solved4.7KViews0likes2CommentsStruggling to create a calculation that uses dates from different tables
Hi, I have a problem where my volume sold is duplicating. This is because some SKU's have 2 recipes - the recipe has changed slightly but it is the same product. We have dates for when these recipes are valid and what I am trying to do is pull back the details of the recipe that is valid at a given time along with the volume for that month. I have created a measure for this - when the month is between the launch date and the discontinued date then "Yes" else "No". That appears to have worked. Then it's a simple case of filtering when Correct Recipe = "Yes". I get what I expect when I do this. However, the problem I have is as the recipe dates and Full Date (month of sale) are in separate tables I had to use the max() function in my measure: Correct Recipe = switch(true(), max(Financial_Data[Full Date]) >= max('OPOH NUTRITION'[Launch Month]) && MAX(Financial_Data[Full Date]) < MAX('OPOH NUTRITION'[Discontinued Month]), "Yes", "No") I want a card with just the volume sold on it, but as my measure uses the max fucntion() it just takes the max launch date etc. overall and does not give me the figures I need. I have also tried to create a column/measure that says if the order month is between the launch and discontinued dates then "Volume" else 0 and then I was planning to use SUMX(). But again I'm struggling to references dates from different tables in the same calculation. Does anyone know how to get around this please? Thanks Michael850Views0likes5CommentsTotal Row of Measure not summing as expected
Hi, We have to pay the council PRN costs for the materials we use in our packaging. We pay this price per case sold, so Cases * PRN Price per case = PRN Costs to pay. These costs changed in April 2023, so what I want to do is for anything before April 2023 I want to do “Volume (cases)” x “PRN Cost per case before” and anything after April 2023 I want to do “Volume (cases)” x “PRN Cost per case after”. For every row I have created a column that calculated the cost using the price before April 2023 (PRN Cost v4 before) and another column looking at the cost using the price after April 2023 (PRN Cost v4 after). I have then created the measure PRNv5. This measure is a switch statement that says if the date is before April 2023 then use the value from “PRN Cost v4 before” and if the date is after April 2023 then use the value from “PRN Cost v4 after” This measure appears to work at the row level however tht Total Row is not equal to the sum of the PRNv5 Column. £249.50 + £167.64 is £417.14, not £426.50 as the Total row suggests. I can't use the sumx() function as it is a measure. However I can't seem to create PRNv5 as a column at all. Any help would be much appreciated! Thanks Michael493Views0likes2CommentsNeed Help with DAX 2-Day Lag Formula return different data sources based on future vs. past
Hi, I am trying to create a DAX formula that will return hours depending on the day. Please help! I am very stuck. For past dates before TODAY and YESTERDAY, I want to return the data from "Actual Hours" measure/column. For TODAY, YESTERDAY and FUTURE DAYS, I want to return the data from "Scheduled Hours" measure/column. I am currently using the below formula but it is not bringing in "Scheduled Hours" for today and future. The hours return for past dates before Yesterday and Today are incorrect. I am comparing this data in a table matrix by bringing in Actual Hours and Scheduled Hours side by side. 2 Day Lag Hours = VAR CurrentDate = SELECTEDVALUE('Tables- Dates'[Date]) VAR Result = SWITCH( TRUE(), CurrentDate < TODAY() - 1,[Actual Hours], //Past: Actual Hours Measure CurrentDate <= TODAY(), [STAR Scheduled Hours], //Today and Yesterday: Scheduled Hours Measure CurrentDate > TODAY(), [STAR Scheduled Hours] //Future: Scheduled Hours Measure ) RETURN Result Thank you!554Views0likes2Comments