This one seems simple but I'm stumped. Hoping someone has come across this one before.
I want to show:
State Category Sales$ if Furniture is the highest Sales$ category for that State
Ex: Arizona Furniture $13,525
However, if Furniture is not the top Sales $ Category I want to show 0 or NULL or "Red Flag". Any could work,"Red Flag" would be best but I'm not sure we can couple an 'ag' with a string.
Ex: Alabama Furniture "Red Flag"
Thanks for any suggestions that get this right!
State Category Sales
Alabama Furniture $6,332
Office Supplies $4,209
Technology $8,969
Arizona Furniture $13,525
Office Supplies $10,006
Technology $11,751
Arkansas Furniture $3,188
Office Supplies $4,565
Technology $3,925
California Furniture $156,065
Office Supplies $142,352
Technology $159,271
Colorado Furniture $13,243
Office Supplies $7,899
Technology $10,966
Let's go part by part. First let's create a [max_sales] field:
{ FIXED [State] : MAX([Sales]) }
This will give you the max sales of each state, among the categories. I'm assuming that's the lowest level of detail (category). If it is not, you can use another LOD calculation to have the figures for each category:
{ FIXED [Category] : SUM([Sales]) }
And use this field on the first calculation.
Now for the next part. You can't mix integers with strings, but you can always convert int to str. I would do:
IF [Category] = 'Furniture'
THEN IF [Sales] < [max_sales]
THEN 'Red Flag'
ELSE STR([Sales])
END
ELSE #I have no idea what you want here
END
Again, if category is no the lowest level of detail, use SUM([Sales]) instead of just sales (and MAX([max_sales]) if Tableau says you can't mix aggregated with non-aggregated fields)
Related
I have a table from a survey that reports the score given to a specific employee, and various columns are there to hold each score for each question. Like this table below:
Now, what I want to do is make a row for each question, and in the original table, each question is a column. And I'd like for example, John, to have 1 entry for each question, and the average of that score stored next to each question like in this table here:
.
This shows clearly what I'm aiming for.
I believe I need some sort of pivot or unpivot table going on, but I'm not too sure on the Power BI DAX syntax for creating a new table.
I currently have a table that provides each Employee once, and columns showing their average score for each question, but that is a bit harder to dice up the way I want to. Code pasted below:
ReportTable =
SUMMARIZE(
ALL ( '360Sample'[Name], '360Sample'[Relationship to person being reviewed]),
'360Sample'[Name],
'360Sample'[Relationship to person being reviewed],
"Employee Satisfaction", DIVIDE(CALCULATE(AVERAGE('360Sample'[Treats others with respect/Truly values employees]))+AVERAGE('360Sample'[Encourages and supports staff in developing their skills])+AVERAGE('360Sample'[Provides effective mentoring]),3),
"Quality Product", DIVIDE(CALCULATE(AVERAGE('360Sample'[Consistently strives to provide products above industry quality standards]))+AVERAGE('360Sample'[Takes ownership of project outcome])+AVERAGE('360Sample'[Ensures quality control always happens on products]),3),
"Client Satisfaction", DIVIDE(CALCULATE(AVERAGE('360Sample'[Fosters open, honest, and consistent communication with clients]))+AVERAGE('360Sample'[Responds quickly to client questions and concerns.])+AVERAGE('360Sample'[Successfully communicates contractual needs and requirements with the Client, including schedules and scope and fee increases]),3),
)
Only difference here is that I have an extra attribute of "Relationship" which I'll also need to include but is less important for now. It makes a row of each employee for every unique Relationship, which is 2.
Hello You need to first use the "unpivot" in Power Query to convert your table into this shape: It is not so hard.
Like this:
Then use this DAX Code:
ReportTable =
ADDCOLUMNS (
SUMMARIZE ( 360Sample, 360Sample[Name], 360Sample[ScoreNum] ),
"ScoreAvg", CALCULATE ( AVERAGE ( 360Sample[Score] ) )
)
And It produces:
I am trying to replace blanks with zero in a matrix visual, but the traditional method of adding +0 is causing another problem. I have the case described below in detail. Thank you so much for any help anyone may be able to offer!
I have a (fictitious) company with 60 employees located in 5 regions (Midwest, Northeast, Pacific, and Southwest). Each employee holds an occupational type (such as chemist, auditor, geologist, truck driver, etc.). Across the entire company, there are 18 different occupational types.
Additionally, each region considers some of the occupations as critical and others as non-critical and the critical vs. non-critical occupation types vary by region. If the occupation is critical for a particular region, the occupational title (e.g. chemist) should appear in the visual and if the occupation is non-critical, the generic title ‘Non-Critical’ should appear instead of the occupational title.
To accomplish this, my PowerBI model has two related tables – employee list (dimension table/many) and occupation list (fact table/one). Each employee on the employee list has a match code that is related to the match code on the occupation list to determine if the occupation is critical or non-critical for that employee’s region. If the occupation is critical, the related field (that will be used on the row field of the visual will be the occupational title. If non-critical, the related field will be the generic title ‘Non-Critical’.
Here’s an example of three records from the employee list fact table:
Image A
And here’s an example of some records from the occupational list dimension table:
Image B
The purpose of the visual is to show the count of employees onboard at two points in time (called FY20 and FY21) by occupational type with a slicer to filter by region.
The employee count is produced using the measure =COUNTROWS(Employee List)
Everything works great at this point. Here is an example of the visual filtered to Midwest, which correctly shows the Midwest Region’s 10 critical occupations broken out by occupational title and the employee counts. (non-critical count also correctly shown)
Image C
And as a second example, here is the view filtered to the Pacific Region showing the Pacific’s 3 critical occupations (non-critical also correctly show):
Image D
My only goal with this visual is to display zero instead of a blank for those cases where there are no employees. When I modify the measure to:
=COUNTROWS(Employee List) + 0
I get the following result (filtering to Midwest for example):
Image E
So, the result is that the formula did replace the blanks with zeros, but now all the entire company’s 18 critical occupations are displayed and not just the 10 for the Midwest. The counts are still correct for the Midwest, but I only want to show the Midwest occupations as they were appearing correctly before I added +0 to the measure. If I try to simply filter them out at the visual level, then they will stay filtered when I switch region where they should be unfiltered.
It seems the behavior is that a blank being replaced by a value (0) means that when there is a combination for which there is no data (such as Midwest/Chemist), the visual will still show 0 as a result for that combination.
I’m looking for anything I can do to replace blanks with zero and not displace the occupation types that don’t apply for the region. I would appreciate any assistance as I’ve been thinking about this for hours and have hit a wall.
Thank you!
I suggest a measure on the following form, written verbosely:
# Employees w/ zeroes =
VAR _employees = [# Employees]
VAR _totalEmployees = CALCULATE ( [# Employees] , REMOVEFILTERS ( 'Employee List'[Year] ) )
RETURN
_employees + IF ( ISNUMBER ( _totalEmployees ) , 0 )
This will first check that the occupation type has employees for the selected filter context, and only tack on a zero if so. The column specified in REMOVEFILTERS() must correspond to whatever you are using in your visualization - it is used to modify the filter context.
It looks like a fairly simple (if possibly temporary) solution is available for this problem by using conditional/advanced filtering on the visual. I set the advanced filter to show when the value is not 0 and this seemed to take care of it. Thank you for the DAX code and I will explore those options as well.
Thanks again!
I've got two tables Fauna_Afetada (animals affected) e Municipios (all cities of the country). A fauna afetada tem a sigla_uf (state initials which the city belongs to) e nome_municipio (name of the city), as well as the Municipios table.
I'd like to create a measure counting the number of deaths (Situação_Int = 0 in table Fauna_Afetada, specify that the animal died) by city (table Municipios). The way to join these tables is by using two columns (the sigla_uf and nome_municipio), because each Municipio in Fauna_Afetada might appear several times. How do I do that?
I'd like to create a measure with the name of the city with the highest number of deaths.
Anyone could help?
The data model is below.
It seems it is a data modeling issue in the first galce,
The model is full of bidirectional relationships that lead to not expect calculations behaviors.
Can you share the file or part of it
Main questions I have:
RegEx practices for statements that are close but not similar iterated through a list of websites when dealing with doubles and text
Should I pull all of the text then parse out what I want in the following code? Or is there a better way?
I am currently trying to extract interest rate data from different lenders using regular expression. I want to use regex because I want to be able to add more URLs as more lenders arise. I want the extracted information to basically take on the form of:
x.xx% - xx.xx% (the low - high bands of the interest rates)
Most of the websites vary in how they present this, some examples:
APR ranges from x.xx% to xx.xx%
Rates range from x.xx% to xx.xx%
x.xx% - xx.xx%
range from x.xx% (AA) to xx.xx% (HR)
Currently I am trying to just grab the paragraph the text lives in and then make substrings off of that to create the final piece of information I need (x.xx% - xx.xx%). Not sure if this is the best method, but would like to crowdsource my issue.
plcompetitors = ['https://www.lendingclub.com/loans/personal-loans',
'https://www.marcus.com/us/en/personal-loans',
'https://www.discover.com/personal-loans/',
'https://www.lightstream.com/',
'https://www.prosper.com/']
#cycle through links in array until it finds APR rates/fixed or variable using regex
for link in plcompetitors:
l = r.get(link)
l.encoding = 'utf-8'
data = l.text
soup = bs(data, 'html.parser')
paragraph = soup.body.findAll(text=re.compile('% APR'))
#using this next if statement to try and iterate through what turned up empty in the initial pass through with the first .compile statement
if paragraph == []:
paragraph = soup.body.findAll(text=re.compile('% - [0-9]'))
print(paragraph)
Which returns this:
[]
[]
[' 6.99% to 24.99% APR']
['\r\n Payment example: Monthly payments for a $10,000 loan at 3.09% APR with a term of 3 years would result in 36 monthly payments of $291.21.', 'The lender’s interest rate (APR) must not be supported by any third-party arrangements such as vehicle manufacturer subvention payments (with rates as low as 0.0% APR), other manufacturer discounts, rate buy-downs by car buying services or any other\n similar third-party subsidized rate offerings.']
['* For example, a three-year $10,000 loan with a Prosper Rating of AA would have an interest rate of 5.31% and a 2.41% origination fee for an annual percentage rate (APR) of 6.95% APR. You would receive $9,759 and make 36 scheduled monthly payments of $301.10. A five-year $10,000 loan with a Prosper Rating of A would have an interest rate of 8.39% and a 5.00% origination fee with a 10.59% APR. You would receive $9,500 and make 60 scheduled monthly payments of $204.64. Origination fees vary between 2.41%-5%. APRs through Prosper range from 6.95% (AA) to 35.99% (HR) for first-time borrowers, with the lowest rates for the most creditworthy borrowers. Eligibility for loans up to $40,000 depends on the information provided by the applicant in the application form. Eligibility is not guaranteed, and requires that a sufficient number of investors commit funds to your account and that you meet credit and other conditions. Refer to Borrower Registration Agreement for details and all terms and conditions. All loans made by WebBank, member FDIC.']
I am trying to do some analytics on PowerBI. I am struck at this logic, where I am trying to Identify the common items with in the group and not common items with in the group.
For Example,
Group Name Contact
GroupA Rock
GroupA Eddy
GroupA Brown
GroupB Rock
GroupB Katie
GroupC Eddy
GroupC Brown
GroupC Katie
If I select GroupA and GroupB then I want to output the Common Items as 1 and not common Items as 3.
The Common Item is Rock
The Not Common Items are Eddy, Brown & Katie.( I am looking to get this as part of my output visual as well)
How can we do this in PowerBI which works dynamically when we select multiple groups (more than 2 as well)?
I would approach this by checking if the number of groups the Contact appears in is the same as the number of groups that you have selected:
Common = IF(COUNTROWS(VALUES(Groups[Group Name])) =
COUNTROWS(CALCULATETABLE(VALUES(Groups[Group Name]),
ALLSELECTED(Groups))),
"Common", "Not Common")
Then you can use these labels inside a second measure to get the count:
Intersect = IF([Common] = "Common",
CALCULATE(DISTINCTCOUNT(Groups[Contact]),
FILTER(ALLSELECTED(Groups[Contact]), [Common] = "Common")),
CALCULATE(DISTINCTCOUNT(Groups[Contact]),
FILTER(ALLSELECTED(Groups[Contact]), [Common] = "Not Common")))
You can then set up a table or matrix using Contact and the new measure Intersect along with a slicer on Group Name.