or
8 TopicsIf, Or, Else not working
I am working with customer data and I am trying to segment them based on various demographic and lifestage information e.g. if someone is 18-21 years old or 35-39 years old and working full time or partime and not married and does not have kids then they belong to 'segment A' else (a different permutation of the variables above and they fall into 'segment b')etc. I have used If, or, and, then and else but it not producting the right results. I tried using SWITCH but it gave me the " the name 'SWITCH' wasn't recoganised. Make sure it's spelled correctly" error, which I belive has something to do with adding table Vs column. My DAX code looks like below; =if [Q1_Age] = "Under 18" or [Q1_Age] = "18-21" or [Q1_Age] = "22-29" or [Q1_Age] = "30-34" or [Q1_Age] ="35-39" and [#"Q6_Employment_Working full time (30 hours or more work per week)"]=1 or [#"Q6_Employment_Working part time (under 30 hours work per week)"]=1 and [Q2_Parent_None of these apply]=1 and [Q3_Marital_Status] = "Single/Never married" or [Q3_Marital_Status] = "De facto/Living with partner but not married" then "SEGMENT A" else if [Q1_Age] = "Under 18" or [Q1_Age] = "18-21" or [Q1_Age] = "22-29" or [Q1_Age] = "30-34" or [Q1_Age] ="35-39" and [Q3_Marital_Status] = "De facto/Living with partner but not married" or [Q3_Marital_Status] ="Seperated" or [Q3_Marital_Status] ="Divorced" or [Q3_Marital_Status] ="Engaged/Planning to marry" or [Q3_Marital_Status] ="Single/Never married" or [Q3_Marital_Status] ="Married" and [#"Q2_Parent_I have a child/children under 18 living with me"]=1 or [#"Q2_Parent_I have a child/children over 18 living with me"] =1 or [#"Q2_Parent_I have a child/children who have moved out of home"] =1 then "SEGMENT B" else... Can someone guide me on how to identify (or fix) the reason why this is not working, please! Thanks!Solved2.6KViews0likes12CommentsA lot of IF and OR statements - Making it run slow
Hi all, I am having some issues with the performance of some of my reports, due to some measures running slow. Some base info: I am connected to an Azure Blob Storage, collecting data in CSV format. I do some cleaning using Power Query The measure(s) in question: Newsletter Permissions For my company there are some different criteria a recipient have to have, in order to be have a newsletter permission, and they are: If any of the following are true: IF( [ComplaintCheck]=1 || [LastEmailCheck]=1 || (It's more than 365 days since you last got an email) [MalformedCheck]=1 || [ValidEmailCheck]=1 || [UnsubscribedCheck]=1 ) OR if ALL of the following are true or BLANK: IF( Created more than 365 days ago First use of app is more than 365 days ago Your last app use is more than 1000 days ago Your last interaction is more than 1000 days ago Your last web use is more than 1000 days ago Your permission is set within the last 365 days ) For all of the above I have made a seperate measure looking like this: IF( OR( NOT(SUM('agillic-targetgroup'[Days Since First Use])<365), SUM('agillic-targetgroup'[Days Since First Use])=BLANK() ) ,1 ,0 ) I have used Power Query to created columns that calculate how many days it has been since the different dates. I can provide a sample set if needed. I hope some of you can help.788Views0likes4Commentsissue on month over month variation metric when using day filter
Hello, I am having the following problem that I cannot solve. I made a chart with bars and lines where the lines show the metric sales MoM that displays the month-over-month variation. Additionally, with a calendar table, I am using a slicer that filters by day to compare sales within a certain range of days. Everything works perfectly, except for the following specific case that I cannot solve. In the table I am uploading, the last recorded day is 5/5/23. If I filter to see the information for days 1 to 4, the metrics work perfectly. But if I filter to see the information for days greater than or equal to the last day recoded, it stops working (for example 1 to 5 or 1 to 8). Does anyone know what I can modify to make it work consistently? I am uploading the Power BI file with the example and the metrics created: https://drive.google.com/drive/folders/1SIBxFXl1CB3n0gnH2GM6CJe9044dHk_M?usp=share_link Thank you very much in advance.496Views0likes1CommentSyntax for Calculated Column to Filter results from three fields using OR logic
Hello! I'm brand new to Power BI. I'm trying to create a calculated column containing a filter for three other columns in the same data sheet using OR logic. I want a calculated column showing me all changes that will need post implementation review. I want to name that column "PIR" and I want a Boolean result in that column Change Type = "Emergency Change" OR Expedited = True OR Resulted in Outage = True I've tried a number of configurations and tried to follow examples I have found in help forums. But I'm just not getting it. This is what I have for starters: PIR = FILTER('Full SharePoint Export'[Expedited]=True || 'Full SharePoint Export'[Change Type] = "Emergency Change" || 'Full SharePoint Export'[Resulted in Outage] = TRUE) My syntax is incorrect. I could really use a little help. Thanks! SarahSolved973Views0likes3CommentsIF/OR Formula Help
Hi, trying to calculate an exchange rate used in a procurement data set. The below formula is throwing the error DAX comparison operations do not support comparing values of type Number with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values. The data being calculated is formatted as a Decimal Number. There are blanks in the data, so I think the error is being thrown over the first part of the OR. Any help would be greatly appreciated. Exchange Rate = IF(OR('Stock Orders'[Exchange Rate For Report Estimates]="",'Stock Orders'[Exchange Rate For Report Estimates]=0),1,'Stock Orders'[Exchange Rate For Report Estimates])Solved1.3KViews0likes4CommentsFilter overide with &&& as well as ||
Hi I am trying to create a list of distinct dates a customers have entered a store by date but only for a specified set of locations. I seem to be running into an error when I try to add more than one location. My data is laid out as follows CustomerID CustomerName PrimaryMembership AccessRule EntryDate Type Location 12345 Bob Full 2DAF 01/01/2022 Cycle Norwich 12345 Bob Full 2DAF 02/01/2022 Cycle Norwich 12345 Bob Full 2DAF 03/01/2022 Cycle Norwich 12345 Bob Full 2DAF 04/01/2022 Cycle Norwich 12345 Bob Full 2DAF 05/01/2022 Cycle Norwich 23456 Jo Full 2DAF 01/01/2022 Car London 23456 Jo Full 2DAF 02/01/2022 Car London 23456 Jo Full 2DAF 03/01/2022 Car London 23456 Jo Full 2DAF 04/01/2022 Car London 23456 Jo Full 2DAF 05/01/2022 Car Norwich 34567 Jane Full 2DAF 01/01/2022 Cycle Clacton 78910 Anne Full 2DAF 01/01/2022 Car Norwich 89101 Terry Full 2DAF 01/01/2022 Cycle London 91011 Michael Full 2DAF 01/01/2022 Cycle Norwich 10111 Steve Full 2DAF 01/01/2022 Cycle London 11121 Alyssa Full 2DAF 01/01/2022 Car Clacton 12131 Martin Full 2DAF 01/01/2022 Car Clacton 13141 Robin Full 2DAF 01/01/2022 Car Norwich 15161 Dave Full 2DAF 10/01/2022 Car Cambridge Using the following I end up with a resulting table that on the face of it seems correct. DISTINCT( SELECTCOLUMNS( FILTER( Entry, Entry[EntryDate] <> BLANK() --&& Entry[CustomerID] = 15161 && Entry[Location] ="Norwich" || Entry[Location] = "London" || Entry[Location] = "Clacton" ), "_EntryDate",[EntryDate] ) ) However If remove the comment from && Entry[CustomerID] = 15161 I would expect the result to be an empty table as they don't have an entry in those locations but I seem to be getting the whole list regardless. If I ammend the code to just have a single location then i get the blank table as expected. I'm assuming something is going awry with the OR element of this but I can't figure out why. I'm using the ID as a test, I will comment out and filter by ID in the report but I have 160000 rows of data so need to do a little sense checking. Help!Solved487Views0likes2CommentsDax Count number of bids submitted filtered by status
Hi all, I think this is a fairly simple one but I must have something slightly off.... or maybe I'm way off!! I'm looking to create a hit rate... I have my bids submitted number (which only includes bids with a submitted date) but would like to create a measure of successful bids submitted. Successful bids = Pipeline Status = Preferred Bidder OR Contract Award OR Status = Won. The below isnt working.... No of Bids Successful = Calculate( COUNTA(Opportunities[Bid Submitted Date]), FILTER(Opportunities, Opportunities[ID_Pipeline Reporting Status] = "Preferred Bidder" || Opportunities[ID_Pipeline Reporting Status] = "Contract Award)) Opportunity Name Bid submitted date Pipeline Status Status Opportunity 1 17/01/2022 Preferred Bidder Open Opportunity 2 18/01/2022 Contract Award Won Opportunity 3 Preferred Bidder Open Opportunity 4 19/01/2022 Bid Submitted Open Any help much appreciated as always 🙂Solved681Views0likes2CommentsFiltering a Multi-Select Slicer via AND instead of OR logic
In Power BI, slicer visuals work by restricting the rows of data accessible by visuals in the report. Multiselecting slicers unions the criteria by giving rows for all criteria. What is not possible with the default way Power BI filters things is to multiselect data with an intersection (using AND instead of OR logic) to only give rows that fit BOTH the selected criteria. For the report I am working on, I was asked to configure a way so that multi-selecting of our filter categories would filter data via this AND intersection opposed to the Power BI default. Other Solutions: Upon initial research (read: extensive googling!) I came across the following four articles which detail different approaches to achieving this. They all generally tackle the issue in a similar way – using measures to compare counts of selected items versus the count of rows matching these selected criteria. Slicer with AND condition in Power BI - RADACAD Apply AND Logic to Multiple Selection in DAX Slicer - SQLBI Changing “OR” to “AND” Logic for Power BI Slicers | by Orysya Stus | Seismic Innovation Labs | Medium Power BI: Implement AND/OR Selection | by ZhongTr0n | Towards Data Science However, due to the structure of the data I was working with and the specific needs of the report, none of these solutions exactly worked. The Data: For the sake of privacy I cannot share the actual data of the report although for developing the right method to replicate this ‘AND’ filter I can show a snippet of the structure of the data I am working with. Requirements: The specific solution I was tasked to create was a way to multi-select a slicer based on [Course] to filter visuals that all concerned the number of distinct Employees (based on unique key field [Email]). Without any of the AND logic implemented, the report looked like the following: You can see we have a count of the number of trainees broken down by different categories (hidden for the sake of privacy). When different courses are selected the data shown dynamically changes to include rows relating to either Course 1 OR Course 2 OR Course 3… and so on. Solution: To change this logic to instead give rows of one table (Employee Head Count) relating to multiple rows in another one (Course 1 AND Course 2 AND Course 3 …): DAX Measures! I have broken down my solution into two different parts corresponding to the two measures I have made. Pt 1. Trainees Count Without any AND logic, our original measure to count the number of employees who had completed training was the following: Trainees = DISTINCTCOUNT('Training Records'[Email]) To implement AND logic, we result in the following: numTraineesCompletedALLSelected = //the number of trainees who have selected all completed courses // count the number of criteria (courses) selected var selectedCourses = VALUES(Course[Course]) var numSelectedCourses = COUNTROWS(selectedCourses) //count number of selected courses completed per trainee var result = COUNTROWS( FILTER( GROUPBY( FILTER('Training Records', RELATED('Course'[Course]) in selectedCourses), 'Employee Head Count'[Email], "SelectedCoursesCompleted", COUNTX(CURRENTGROUP(), [Course]) ), [SelectedCoursesCompleted] >= numSelectedCourses) ) //if courses are being filtered: filter with AND condition //else count trainees normally return IF(ISFILTERED(Course[Course]), result, DISTINCTCOUNT('Training Records'[Email]) ) Let’s break this down, To start off we create two variables selectedCourses and numSelectedCourses which extract the courses we have selected via the slicer. Then we have the result variable – the main chunk of the logic. If we focus into the middle bit we have a GROUPBY function wrapping COUNTX with a filtered table. What this does is, from our training records table filtered to only have rows corresponding to the selected criteria, we count the number of courses (as per the COUNTX) grouped by each employee email. This gives us a table for each employee with a corresponding count of how many of the selected courses they have completed. We then further filter this resulting table to only give us employees who have completed at least the same number as the amount of selected courses. The final function is to COUNTROWS of this table to provide a number of how many employees have completed ALL of the selected courses. The final return part of the measure has an extra logic check to see if our criteria is being filtered at all. If it is, we return the result just calculated, if not, we default back to the usual way to count the number of employees. This new measure numtraineesCompeltedALLSelected (pending a name improvement lol) is what we use to replace the original Trainees measure. Pt 2. Count Courses Per Trainee While the previous measure sorts us out for visuals directly using the count of trainees (eg. Our bar graph, or card), what this does not account for is our table visualisations which have data rows corresponding to individual trainees from the Employee Head Count table. To solve this issue, I created a second measure, coursesCompletedPerTrainee = // count the number of criteria (courses) selected var selectedCourses = VALUES(Course[Course]) var numSelectedCourses = COUNTROWS(selectedCourses) // count the number of courses per trainee var coursesPerTrainee = COUNTX( FILTER('Training Records', RELATED(Course[Course]) in selectedCourses), 'Training Records'[Email]) var ANDCheck = IF(coursesPerTrainee >= numSelectedCourses, 1) //return non-blank if courses are not being filtered return IF(ISFILTERED(Course[Course]), ANDCheck, "Non-Blank") Looking very similar to our previous measure, our main difference is that this measure no longer uses a GROUPBY function. Instead, our return value is the number of courses (of the selected courses) completed per trainee (calculated with the COUNTX function). This is then used to filter our table by If we are not filtering at all we simply return a string “Non-Blank” which avoids errors when no criteria is selected. Summary When attempting this solution I found it necessary to have two measures to achieve two main things: 1) A total count of trainees who had completed selected courses (pt. 1) and 2) a measure by which to filter table visuals to only return relevant employee records (pt. 2). This is the main difference I found between my solution and the four previous articles I read in research. I found the difference in how the data I was using was structured compared to the sample data in solutions brought about this requirement as I was concerned with counting the records in one table (Training Records) grouped by the rows of another (Employee Head Count). I would be very interested in hearing of a way to optimize this and perhaps result in only one measure which can be used for the two purposes – the similarity in their code makes me believe this may be possible. For the time being however, I have developed this as the solution to meet the needs of the project as it results in the relevant output being provided for the report.Solved8.9KViews1like4Comments