I'm just after some help in writing the below IF statement in Tableau. I want to identify when a brand name CONTAINS "McDonald's" but also tell me if the person has shopped at one or two or three or four etc. competitor brands (there are 20 brands listed under [M Brand Name]). This is what I have at the moment but it keeps returning "McDonald's and six or more brands"
IF CONTAINS ([M Brand Name], "McDonald's") AND {COUNTD([M Brand Name])} <=2 THEN "McDonald's plus one brand"
ELSEIF CONTAINS ([M Brand Name], "McDonald's") AND {COUNTD([M Brand Name])} <=3 THEN "McDonald's plus two brands"
ELSEIF CONTAINS ([M Brand Name], "McDonald's") AND {COUNTD([M Brand Name])} <=4 THEN "McDonald's plus three brands"
ELSEIF CONTAINS ([M Brand Name], "McDonald's") AND {COUNTD([M Brand Name])} <=5 THEN "McDonald's plus four brands"
ELSEIF CONTAINS ([M Brand Name], "McDonald's") AND {COUNTD([M Brand Name])} <=6 THEN "McDonald's plus five brands"
ELSE "McDonald's and six or more brands"
END
Related
I'll explain my problem with an example:
I have three tables: one of dates, another of employees and another of departments.
There are two relationships:
dim_date[date_id] -> dim_employee[start_date_id]).
dim_department[department_id -> dim_employee[current_department_id]
dim_employee
name
current_department_id
start_date_id
Employee 1
1
20210701
Employee 2
2
20210701
Employee 3
2
20210901
Employee 4
1
20220201
Employee 5
2
20220201
dim_department
department
department_id
Purchase department
1
Sales department
2
I want to count how many employees each department had, for example, in February 2022 (using a slicer).. I've tried this:
num_employees_purchase_department =
CALCULATE(
DISTINCTCOUNT(dim_employee[employee_id]),
dim_employee[current_department_id]=1
)
However, since the relation is made through start_date_id, I only get the new hires of each department (one for the sales department and one for the purchase department) and not the total number of hired personnel.
The result that I'm looking for:
Employees in Purchase Department: 2
Employees in Sales department: 3
Thank you so much!
Try to make dim_date - dim_employee relationship inactive (in Data model view) and add an extra condition into your measure:
CALCULATE(
DISTINCTCOUNT(dim_employee[name]),
dim_employee[start_date_id] <= MAX(dim_date[date_id])
)
Don`t forget to use USERELATIONSHIP() inside your other measures where active dim_date - dim_employee relationship is necessary.
I'm trying to calculate a simple sum of sales for different products but i have a visualization problem.
I have 2 different tables:
"Master data" where i can find all the informations about a porduct (product ID, description etc)
"total sales" where i can find for each product_ID the total sales amount
These tables are connected by a relationship based on the "product_ID".
I have created a table with product_ID (from "Master data") and total sales (from "total sales") but it returns the same amount of sales for every product ID (the sum of sales of all products)
Exemple:
product_ID_1 100€
product_ID_2 100€
product_ID_3 200€
I visualize the incorrect values like this:
product_ID_1 400€
product_ID_2 400€
product_ID_3 400€
Thanks in advance!!!
Ersilia
This is absolutely impossible!
If you put 'Master Data'[Product ID] next to [Sum Total Sales] in one table visual, then 'Master Data'[Product ID] will filter [Sum Total Sales].
If you see the Total of [Sum Total Sales] in every row, then YOU ARE NOT FILTERING, because you clearly don't have a relationship between 'Master Data' and 'Total Sales'. Check that in the Model view: The line is either missing, or dotted (inactive).
But with the given sample data from above you should have a one-to-one relationship between the Product ID's, although in general this will be a one-to-many relationship, since every product is probably sold more than once.
I'd recommend using more general sample data to check this out and not to use the same names for tables and their columns and esp. not 'Total' everywhere, so that you don't end up with such confusing expressions like "Total of [Sum Total Sales]". This is asking for trouble.
is it possible to use Power BI DAX to search for a text match between two columns in the same table subject to row context?
In the example below, the table shows profiles associated with two users; A & B. Some of these profiles are not compatible with others and this is indicated in the third column.
The fourth column is for the DAX output which aims to highlight incompatibilities across a user's list of profiles. The output in the fourth column is what I expect but the DAX I've written so far (below) isn't working.
Please note that the checks between columns 2 & 3 need to be with respect to each user.
Any help would be much appreciated!
Column =
var userProfiles = CALCULATETABLE(
SELECTCOLUMNS( 'Table1', "Table1Profiles", 'Table1'[Profile]),
FILTER( 'Table1', Table1[User] = "A" )
)
RETURN
CONCATENATEX(
userProfiles,
IF (
SEARCH(
FIRSTNONBLANK(userProfiles,1), ProfilesTest[Incompatible with],, BLANK()
) <> BLANK(),
FIRSTNONBLANK(userProfiles,1),
""
)
)
Example
User
Profile Name
Incompatible with
Incompatibility Detected
A
Dispatcher
Purchaser
A
CEO
Director
Director
A
Secretary
A
Director
CEO, Mechanic, Tester
CEO
B
Mechanic
Director
B
Purchaser
Dispatcher
I am trying to calculate 'TimeSheet Team PV'[Time (h)] * 'Position History'[Salary]
Data model:
TimeSheet Team PV" table:
"Position History" table:
In the Position History table, I have some employees which were promoted and appear as having different periods during different periods in the company, with different salary. Can I join somehow these values based on Start Date, End Date (Position History table) and Work Date (TimeSheet Team PV tables) + Name?
I would like to generate new column in the TimeSheet Team PV table, with the calculation above.
You'll need to write some logic to make sure it uses the Work Date column. Something like this:
Cost =
VAR WorkDate = 'TimeSheet Team PV'[Work Date]
RETURN
'TimeSheet Team PV'[Time (h)]
* CALCULATE (
SELECTEDVALUE ( 'Position History'[Salary] ),
'Position History'[Start Date] <= WorkDate,
'Position History'[End Date] >= WorkDate
)
I discovered PowerBI few hours ago and I am trying to render a new graph, pretty complex from my data.
My subject:
I have a list of employees from my society with some information (name, location, seniority, ....) inside a table named Suivis de mission.
I'm focusing on seniority column. I have to display, monthly, the number of employees which has less than 3 seniority years, more than 3, more than 5 and more than 8.
This field is calculed through another field (date_de_changement_de_mission) by the next formula:
(today - date_de_changement_de_mission) / 365
It gives me a number according to the seniority years (above in french)
My experimental work:
I tried to make some things and this is what I have up to now.
I created a new table with months (string column1 and int column2) and the third column according to the number of employee with less than 3 seniority years for each month.
This is the formula that I'm trying to implement in order to get the number but I have lot of mistakes :
Nbr_inf_3_ans = SUMX('Suivis de mission';
IF(
'Suivis de mission'[Activité] = "En poste";1 &&
DIVIDE(
DATEDIFF(01/01/2019;'Suivis de mission'[Date de changement de mission].[Date];DAY);365)
;"null"))
The formula must contains several conditions :
Field 'Suivis de mission'[Activité] has to be : "En poste"
Loop over each month in my table (if the month is not targed, display 0)
I'm a bit lost.
Assuming that:
You want to do it in Power Query Editor
You already created the "seniority" and "month" ("mois*") columns
You are not worried about the year (you are really grouping just by month)
Then these steps may help you to begin:
Create a custom column name "IsLesserThan3" with the formula:
if [Seniority] < 3 and [Activité] = "En poste" than 1 else 0
Change the formula to include the requirement about "if the month is not targed" (i didn't get what it means, sorry).
Choose "Transform" (menu), then "Group By", then basic, set group by = month, give it a name ("Nbr_inf_3_ans"), set operation = sum, set column = IsLesserThan3
EDITED
New extra assumption:
There is a second table with month description and month number and you want to create the new column there ("Nbr_inf_3_ans") and fill it, probably to grant all the months are there (including those with no occurrences).
With this new assumption in mind, the approach will be to join the two tables and do the same thing:
Create a custom column named "IsLesserThan3" with the formula:
if [Seniority] < 3 and [Activité] = "En poste" than 1 else 0
Change the formula to include the requirement about "if the month is not targed" (i didn't get what it means, sorry).
Change the type of the new column to integer (click the icon to the left of the column name).
Create a custom column named "Mois_int" with the formula:
Date.Month([date_de_changement_de_mission])
Then join the tables by month. To do that, select the other table and choose "Transform" (menu), then "Merge", then let the second table selected and select the first table as the "bottom" table, select columns "Mois_int" in both tables, set "join kind" = "left outer".
PowerBI will create a new column wich name is the name of the first table. Click the arrows icon in that column header and choose "aggregate" and mark only "sum of LesserThan3".