I have two tables, one with unique ID's ('Risk Finder') and one with many ID's ('All Accidents full'). In 'All Accidents full' there is a column with binary 1s and 0s to denote if something happen within a time range specified ('All Accidents full'[Three Year BAU]). In 'Risk Finder' I'm trying to create a column that counts the number of rows with a 1 in that binary column for each unique ID.
I've tried a combination of Calculate(Countax), Calculate(Sum) and Countrows, but nothing seems to work.
CALCULATE(COUNTAX('All Accidents full','All Accidents full'[Three Year BAU]),'Risk Finder'[ID])
Any help would be greatly appreciated
I'd think you just need COUNT and a filter.
CALCULATE (
COUNT ( 'All Accidents full'[ID] ),
'All Accidents full'[Three Year BAU] = 1
)
Related
I am struglling to getting top 25 unique customers when filtering the table using Alert_Id. Basically, I have these columns in table which you can find below. The goal is to show top 25 unique customers based on highest value. The Item can be repeated but name has to be unique. I have tried so many different things but nothing seems to be working as expected because of Multiple customers have used multiple items and hence I am getting duplicate rows. The table has to be dymic because whenever user filters the table using Alert_id it should return those top unique customers that associated with Alert_id(Alert_id is a single selection). So whenever user select their Alert_id that table should display their data. I have tried below measure,
First I created calculated column to break the tie for price because many Item shares the same price:
max price = Table[PRICE] + RAND()
Then I created another column to get max price for the customer name:
MAX column for table = CALCULATE(MAX('Table'[max price]), ALLEXCEPT(Table, Table[CUSTOMER_NAME]))
Then I created calculated table using these columns:
SELECTCOLUMNS(
FILTER(Table, Table[max price]=Table[MAX column for table]), "Name" ,Table[CUSTOMER_NAME],"Item",Table[ITEM], "PRICE",Table[MAX column for table], "Alert_ID", Table[ID], "DATE", Table[REQ_DATE], "ITEM_COUNT", Table[PK])
But, this is giving me all unique customers with the MAX value and I am getting blank table when I filter with Alert_ID even thought it has data but the customers are not with the MAX value. Basically, It's not dynamically capturing max values for each customer_name when filter is applied. And, I if there are multiple rows with same customer name which can have same exact value then I would choose any random row without considering which ITEM it is. I just want top 25 unique customers for one Alert_ID.
Here is the sample data,
Here is expected output if I select Alert_ID = 123 from filter and it can be different when I select different Alert_ID.
FYI: I have tried topn with max price and even with RANKX but no luck. I always endedup having multiple customers.
Any help or lead will be highly appreciated!
I was able to figure out how to get unique values. Here is the solution that worked for me.
First, I created calculated column with my price column and RAND function to break the ties:
sum value = Table[PRICE] + RAND()
Then, I have created one measure that calculates the rank:
rank with table = RANKX(CALCULATETABLE(VALUES('Table'[ITEM]), ALLSELECTED('Table'[ITEM])),CALCULATE(SUM(Table[sum value])), ,DESC, Dense )
Then I applied the filter on NAME column to get top 25 based on sum value calculated column. Also, dragged my measure on filters pane and applied the filter where Rank with table = 1.
That's how I got unique names with highest valued ITEM.
So this is a one I have been cracking my head because I know there has to be a way.
I have a Top 10 Country column ranked based on sales. Unfortunately in my data source there were null values for countries, no value was defining it, and in order to fix those null values I replaced them with a string Unknown. The idea was to create Other category and everything not in the top 5 sum in there and finally have a total of all the values.
I started with ranking column defining,
Country Sales Rank = RANKX(
ALL (Country[Country Name]),
CALCULATE([Sales], ALLEXCEPT(Country,Country[Country Name])), ,DESC
The problem is when adding the rank to the countries the Unknown sales are top 4.
Unknown in the top 5
I also tried categorizing the countires in Other and then grouping them; one group for top 5 another Other group for the rest but the Unknown still remains in the top 4.
Country Top 5=
IF(
Country[Country Sales Rank] IN {1,2,3,4,5}, Country[Country Name], "Others")
Ideally this is what I am going for:
End result
Did anyone come across a similar issue I am having? Thanks!
I am trying to count the number of employees at a certain branch over different periods of time. I am providing a sample below.
I have an employee table:
A date table:
I have used the formula below to count the number of employees at the "Doe" branch at certain periods of time. I have created inactive relationships between the two tables. I am using the "Year" and "QTR" columns from the date column as filters.
Number of Employees =
CALCULATE(COUNTROWS(tEmployee),
FILTER(VALUES(tEmployee[Enter Date]),tEmployee[Enter Date] <= MAX(tDates[Dates])),
FILTER(VALUES(tEmployee[Leave Date]), OR(tEmployee[Leave Date] >= MIN(tDates[Dates]),ISBLANK(tEmployee[Leave Date]))))
However, my numbers seems to add up/mess up over the two years which is something I am trying to avoid. Like here for example, my number of employees shows 4 for the year 2019 Q1:
Whereas, I have only had one employee in the branch during that time.
I am trying to make this as dynamic as possible. However, I guess I am having trouble trying to figure out what I am doing wrong here.
Any help would be appreciated.
I've started to manage PowerBi from a couple of weeks so i'm a little bit confused about some things.
My problem is that i need a Matrix in my dashboard with percent values but i want the total in number value because the total of a percent of row shows me always 100% and i dont know about the number i'm working
This is my Matrix with percentage values
This is how i want the total of row returns me but with the columns values ins percentage
I've tried to make a measure counting the values
COUNT(OPSRespuestas[answer])
After that turn off the total of rows and add this measure to the values in my matrix but this is what i get
This is my table after trying add a measure with the total
It returns me the total for each of the columns and not the total of all my rows.
These are the tables i'm working with
This my top header values
This is my left header values
The answer column is what i need to count
This is my relationship between this 3 tables although i have many more intermediate table aside from this 3 as you're going to see in the next picture:
My relationship tables
So finally what i need is that this matrix shows me the total of answer in percentage for each of departments and group of questions and then show me total by department but with number value
The problem you are experiencing has to do with context. Each row is seen as it own total population hence the 100% total. Each column in this row is evaluated against the total of that row to provide a percentage value.
In addition to adding a custom measure to replace the total, you could also consider computing a percentage against the grand total of all dimensions. This means that each cell gets evaluated against the the total of all rows and columns. In this ways the cell value would change compared to your first table but the row total does not evaluate to 100% anymore.
SUM ( [Value] ) / CALCULATE ( SUM ( [Value] ) ; ALL ( 'Your Table' ) )
I couldn't find an answer for my issue elsewhere, so trying my luck here.
I have sales table and my final result should determine if there were sales made for same person in specific period of time, for example within 7 business days. for example:
For ID 123 I have to flag it that sale for products A,B,C where within specified period.
For ID 1234 only sales of products A and B meet the criteria product C was sold in irrelevant time frame.
I've created a date table with indicators that determine for each date if the date is a working day, but i am struggling to calculate the relevant last working day
For example: I need that for 01/01/2019 i will get 10/01/2019 date, based on NUMOFDAYS and FinalWorkday = TRUE, which basically means that i have to count NUMOFDAYS times TRUE statement for each date and return corresponding date.
After that step done I think that it would be pretty easy for me to determine if the sale for a person was made in specific time frame.
If someone can give me direction for that much appreciated
Thank you in advance
You could use a DateTable like this one:
I used the following DAX-expressions for the calculated columns:
nrDays = 7
isWorkDay = WEEKDAY('DateTable'[Date],2) < 6
rankWorkingDays = RANKX ( FILTER ( DateTable, DateTable[isWorkDay] = TRUE () ),
DateTable[Date] , , ASC )
LastWorkDay = LOOKUPVALUE ( DateTable[Date],
DateTable[isWorkDay], TRUE (),
DateTable[rankWorkingDays], DateTable[rankWorkingDays] + DateTable[nrDays])
This issue can be solved by the following, since three are non-working days/holidays we can filter them out via POWERQUERY, than add an Index Column and Another column Which is basically Index column + Number of days wanted, then simply merge duplicate of dates query on Index+number of days wanted column on Index column. And we get the correct date