countx
16 TopicsHow to apply Countif based on measure value
Hi, I have currently 2 tables as follows Table 1 (Multiple Side filter apply to get the measure value) Year Resource Measure Value 2024 A 1 2024 B 2 2024 C 0 2024 D 0 2024 E 3 2024 F 2 Table 2 (Same Multiple Side will be apply to get the measure (Countif) value) Value (Static Value from 0 - 10m Measure value in table 1 will only be 0 - 10) Measure (Countif) 0 2 1 1 2 2 3 1 How can I get the measure (Countif) based on the Resource count. ThanksSolved581Views0likes2CommentsUsing countx with three conditions
Hi everyone, I have a table of risks and the calendar table. I need to calculate the number of risks that were open in a certain period, where their status is high and the date closed should be within 14 days from the date opened, if more than 14 days, then the risk is non compliant. I have used the following measure but I am getting blank values: Non Compliant Vulnerabilities = CALCULATE( COUNTX(FILTER('Web Vulnerabilities', 'Web Vulnerabilities'[Date Opened]<= MAX('Calendar'[Date]) && 'Web Vulnerabilities'[Risk Description] = "high" && 'Web Vulnerabilities'[Date Closed] > DATEADD('Web Vulnerabilities'[Date Opened],+14,DAY)),'Web Vulnerabilities'[Title]),CROSSFILTER('Web Vulnerabilities'[Date Opened],'Calendar'[Date],None)) Any suggestions?391Views0likes1CommentCOUNTX running very slow - anyway to improve performance?
Hello, We are calculating XIRR in PBI. There are several associated measures. Some of the measures run slow - example of one below. Any idea how to speed up or why this is occurring? Relatively speaking, there are not many records in the table - about 500k. And we use DirectQuery. Slow running measure is: XIRR_BeginRMV_Date_IsBefore = VAR StartDate = [XIRR_BeginDate] VAR HowMany = CALCULATE(COUNTX(XIRR_Lookup,XIRR_Lookup[TransactionDate]),XIRR_Lookup[MappingName]="Reported Market Value", XIRR_Lookup[TransactionDate]<StartDate) RETURN IF(COALESCE(HowMany,0)=0,"AFTER","BEFORE") And mainly the slow part is VAR HowMany. Thanks, DanSolved872Views0likes2CommentsDAX Measures for counting time differencies by speed category
Hello Community, I am trying to calculate through only DAX Measures the quantity of tickets being responded in 4 categories of speed (Difference between the timestamp of ticket creation minus the timestamp of ticket_start_to_resolve) : <1 minute, 1 to 5 minutes, 5 to 60 minutes, >1 Hour What I have tried until now 🙂 1.- Perform a measurement called SpeedResponse SpeedResponse = SUMX(factTable, 'factTable[ticket_response_timestamp] - 'factTable[ticket_creation_timestamp]) 2.- (integration of 2.- and 3.- former steps into one Measurement). <1 min_total = //I know the following is not working, but in that way you will see the idea behind calculating the total of rows (tickets) with specific speed so that I can count them and then filter that total ammount with the additional filters later. var _lessThan1Minute = COUNTX(factTable, CALCULATE([SpeedResponse], IF(AND(HOUR([SpeedResponse])=0, MINUTE([SpeedResponse])<1),1,0)) ) var _lessthan1MinuteFiltered = CALCULATE(_lessThan1Minute), FILTER(ALL(factTable[ticketOrigin]), ALL(factTable[ticketOrigin]="outsourcing") return _lessthan1MinuteFiltered Thank you so much in advance community!750Views0likes2CommentsCreation of DAX measures instead of calculated columns for calculating time speed % categories
Hello All, I am trying to calculate through only DAX Measures the quantity of tickets being responded in 4 categories of speed (Difference between the timestamp of ticket creation minus the timestamp of ticket_start_to_resolve) : <1 minute, 1 to 5 minutes, 5 to 60 minutes, >1 Hour Right now it is calculated in the following steps: 1.- Calculated the difference of timestamps from the two factTable timestamps previously described and named that column as "responseSpeed" -> Performed in PowerQuery 2.- Creation of 4 calculated conditional columns from the previous "responseSpeed" calculation and marked each row as 1 if it is categorized as <1 minute, 1 to 5 minutes, 5 to 60 minutes or >1 Hour ->Perfomed too in Power Query 3.- Calculation of measures for totals by category with additional specific filters related to the business thanks to CALCULATE function and FILTERS from other specific columns. ->Those measures are calculated in DAX and they are calculated like CALCULATED(SUM(), filtered(all(columns, columns="value") of the previous calculated columns in Power Query and filtered. 4.- Finally, those 4 measures in DAX are divided by the total quantity of tickets created so that We have the calculation for every % from each category. ->Performed in DAX and examples like: % <1min = [<1min] / [Total numbers of tickets] So, what is the deal? I am trying to integrate steps 1.- and 2.- in DAX Measures too in order to free space for the .pbix size and later on the model in the PowerBI service. Calculated columns are not considered as the space occupied is higher even than the steps performed What I have tried until now 🙂 1.- Perform a measurement called SpeedResponse SpeedResponse = SUMX(factTable, 'factTable[ticket_response_timestamp] - 'factTable[ticket_creation_timestamp]) 2.- (integration of 2.- and 3.- former steps into one Measurement). <1 min_total = //I know the following is not working, but in that way you will see the idea behind calculating the total of rows (tickets) with specific speed so that I can count them and then filter that total ammount with the additional filters later. var _lessThan1Minute = COUNTX(factTable, CALCULATE([SpeedResponse], IF(AND(HOUR([SpeedResponse])=0, MINUTE([SpeedResponse])<1),1,0)) ) var _lessthan1MinuteFiltered = CALCULATE(_lessThan1Minute), FILTER(ALL(factTable[ticketOrigin]), ALL(factTable[ticketOrigin]="outsourcing") return _lessthan1MinuteFiltered Thank you so much in advance community!1KViews0likes4CommentsFiltering 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.9KViews1like4CommentsFilter countx of a measure
I used the following measure MEASURE Capacity_Share = CALCULATE(100 * DIVIDE(SUM('19981201 Victoria'[Wind - GWh]),'19981201 Victoria'[MEASURE_PowerBiComm])) to plot the following bar chart. Next to the bar chart I am trying to show a table with the months that are < 60. With the following measure MEASURE Quiet_Months = COUNTX(VALUES('19981201 Victoria'[date]),[MEASURE Capacity_Share]) I get But how do I filter count for measure < 60?Solved2.1KViews0likes8CommentsHow to count a rank
Hello, I like to count the rank of prices. I have the following (example) table: article price Account_No Account_Name Group1 Group2 A 9 60000 Hans 525A EPS A 10 50000 Meier 525A EPS A 11 40000 Schulz 525A EPS A 12 30000 Friedel 525A EPS A 13 20000 Thomas 525A EPS B 20 60000 Hans 525A EPS B 22 20000 Thomas 525A EPS B 10 40000 Schulz 525A EPS C 30 50000 Meier 525A EPS C 32 60000 Hans 525A EPS C 11 40000 Schulz 525A EPS D 12 50000 Meier 925A EPS D 13 40000 Schulz 925A EPS D 10 30000 Friedel 925A EPS E 9 20000 Thomas 925A EPS E 20 60000 Hans 925A EPS E 22 20000 Thomas 925A EPS E 10 40000 Schulz 925A EPS F 30 50000 Meier 925A EPS F 32 60000 Hans 925A EPS With the both measures: Price_:=MAX(Prices_History[price]) Preis_Rank:=RANKX(ALLSELECTED(Prices_History[Account_Name]);[Price_];[Price_];;Dense ) I can analyze the data in a PivotTable like this (works perfekt): Now, what I need is (a measure) to COUNT the Rank per ACCOUNT and Group1, this should be like this: (I think) I can't use a calculated column with the rank, because I will use a slicer for account and Group2, so I need a dynamic rank. Can anybody help with this?Solved1.4KViews0likes3CommentsCount ID and Chart Occurrence
I want to count how many times an ID shows up in a given time frame and show that as a chart. I created a column that converts the date into the week of the year. What I am trying to show is how many times someone came into the building in a given week. Table_1 ID Date Week 1234 1/1/2022 Week 1 1234 1/2/2022 Week 1 1235 1/1/2022 Week 1 Chat Frequency 1 2 3 4 5 Week 1 1 2 Week 2 Week 3 ….Solved1.3KViews0likes3CommentsI want to create a table for a report where I can get the count of uses connected by hours
I have a table with users that start and end a connection Table1 Users START_TIME_UTC END_TIME_UTC User1 2019-07-12 01:00:31.000 2019-07-12 04:30:00.000 User2 2019-07-12 02:22:00.000 2019-07-12 04:22:29.000 User1 2019-07-12 03:14:28.000 2019-07-12 04:20:00.000 User3 2019-07-12 01:05:00.000 2019-07-12 06:05:24.000 I create a table in DAX with DATETIME increasing un hour until today Table2 DATETIME COUNTUSERSCONNECT 2019-07-12 01:00:00 0 2019-07-12 02:00:00 2 2019-07-12 03:00:00 3 2019-07-12 04:00:00 4 2019-07-12 05:00:00 1 2019-07-12 06:00:00 1 2019-07-12 07:00:00 0 I don't know how calculate or COUNTUSERSCONNECT, it should check datetime with table1 and count how many users are connected in this hour. I try it, but doesn't work COUNTUSERSCONNECT = COUNTAX ( table1, AND ( table1[START_TIME_UTC] < table2[DateTime], table1[END_TIME_UTC] > table2[DateTime] ) ) It count everthing.Solved906Views0likes2Comments