I hope you can help me with a complicated problem.
I am trying to make a measure which calculate the “weighted distribution %” of a product.
The business definition for this calculation is:
“In a customer Chain we have a number of customers which buys a specific product(selected). We need to find out how much volume these “BUYING customers” buys of the whole PRODUCT GROUP (which this product belongs to) and compare it to the volume of the PRODUCT GROUP bought by ALL customers in the Customer Chain.”
Example (calculation):
Product (selected)=”Product 1”
Number of ALL Customers in “Chain 1” = 18
Volume of PRODUCT GROUP bought by ALL customers in chain = 10.915
Number of BUYING customers in “Chain 1” (who have bought “Product 1”) = 8
Volume of PRODUCT GROUP bought by BUYING customers in chain = 6.945
Calculation:
Weighted distribution % =
Volume (BUYING Customers in chain) / Volume (ALL Customers in chain) = 6.945 / 10.915 = 63,6%
Example (Calculation setup in PBI):
Now, my datamodel is this (simplified):
NOTE(just for info): you may ask why I make a customer count on both “D_Customer” and “F_SALES”, but that is because I can make a customer count on specific transaction dates I F_SALES, ande these I don’t have in D_CUSTOMERIf I set the the following filters:
Chain= “Chain 1”
Product=”Product 1”
I get the following table:
I then calculate the volume on the PRODUCT GROUP with the following measure
Volume (PRODUCT GROUP) = CALCULATE('F_SALES'[Volume];ALLEXCEPT('D_PRODUCT';'D_PRODUCT'[Product group]))
And add it to the table:
Now I have the “Volume (ALL Customers in chain)” part for my weighted distribution calculation.
My problem is how I make a measure, which shows the Volume for the BUYING customers only?
I have tried to make the following calculation, which brings me close:
Volume (BUYING Customers) =
VAR BuyingCustomers_=CALCULATE([Number of Customers(F_SALES)];FILTER('F_SALES';NOT(ISBLANK('Sold to trade'[Customer ID]))))
RETURN
SUMX(SUMMARIZE(D_Customer;D_Customer[Customer Chain];"volume";CALCULATE('F_SALE'[Volume];ALLEXCEPT('D_Product';'D_Product'[Product Group]);FILTER('F_SALE';NOT(ISBLANK(BuyingCustomers_)))));[volume])
Result:
But, as you can see, the volume doesn’t aggregate to “PRODUCT GROUP”-level ?
What I need is this:
Which will give me the measure necessary for my calculation:
Can anyone bring me the missing part?
It will be greatly appreciated.
Br,
JayJay0306
Related
I have a table with a hierarchy Area/Region. I want to filter a region and see a card with that region sales and another card with the sales of the Area the region is from (one level above the hierarchy).
I can do that with a table, attached the example, where the fist column shows the sales and the second the sales of one level above the hierarchy. What I need is, replicate this with cards and filters so, if i filter C100 one card shows 1.9% and the other 22.8%.
My formula:
Above hierarchy = SWITCH(True, ISFILTERED('BD'[Region]), CALCULATE(FACT[Sales], all('BD'[Region])), ISFILTERED('BD'[Area]), CALCULATE(FACT[Sales], all('BD'[Area])),FACT[Sales])
Something like this?
VAR areaValue =SelectedValue('BD'[Area])
RETURN
CALCULATE(
sum('BD'[Sales])
,all('BD'[Region])
,'BD'[Area]=areaValue
)
For a region level it should work either.
I have an employee dataset and I'm trying to display the proportion of BAME staff only as a KPI. My dataset has duplicate lines (staff who have more than 1 role) and so I have to use a distinct count of their staff IDs (i.e. cannot use measure values or SUM) as I want to measure ethnicity per person not per role. The only way I can get the % of BAME across the population is by having all other categories visible however I am looking for a way to display the % of BAME across total only. For example in a table calc BAME = 12%, Non-BAME=85% and Unknown=3% - I want to keep the 12% only to put on my dashboard.
I've not needed to do this in Tableau before and I'm quite new to the software. Is there a way to do this? I thought that perhaps I would need to do an IF statement similar to Excel but the below syntax returns an error.
IF [Ethnic Group]="BAME" THEN COUNTD([Staff ID]) / COUNTD([Staff ID]) END
Thank you so much in advance!
COUNTD(IF [Ethnic Group]="BAME" THEN [Staff ID] END)/COUNTD([Staff ID])
I have a Power Bi dashboard tracking several metrics since the beginning of last month . Some of the comparisons I make are MTD vs Last MTD count of metrics like Total users, No of posts and connections made.
MTD(June) and LMTD(May) were working well last month(June) but when we moved to a new month(july) the numbers are off.
Here's my measure
MTD_Users = CALCULATE(COUNTROWS('reporting profiles'), FILTER('reporting profile', MONTH('reporting profile'[date_created])=MONTH(TODAY())))
LMTD_USERS = CALCULATE(COUNTROWS('reporting profiles'), FILTER('reporting profile', MONTH('reporting profile'[date_created])=MONTH(TODAY())-1))
Since July 2nd these measures are not displaying correct figures for MTD(July 1st) and LMTD(June 1st)
Any advice/assistance will be highly appreciated
You need to ride off contex filter and that mean we must use function ALL or REMOVEFILTERS;
https://dax.guide/removefilters/
https://dax.guide/all/
LMTD_USERS = CALCULATE(COUNTROWS('reporting profiles'), FILTER(ALL('reporting profile'[date_created])), MONTH('reporting profile'[date_created])=MONTH(TODAY())-1))
I am trying to find products that my companies stores in multiple facilities. I have a that shows the unique:
State
City
Location
And a fact table that shows the Inventory details by location ID
. The location in Inventory corresponds to the Location in the locations table and allows me to bring in the actual city/state of the inventory.
I am trying to create a measure that will give me a count of how many States a product is associated with (essentially, how many states is the inventory item in, based on location).
I wrote a similar measure that shows how many unique locations the item is in:
Count of Location =
COUNTROWS(
DISTINCT(inventory_details[LOCATION])
)
My approach for the Count of State measure doesn't work beacuse the table is upstream:
Count of State =
COUNTROWS(
DISTINCT(locations[STATE])
)
This screenshot shows that the relationships and data are established correctly and when a particular product is in the scope of a matrix, I can see what the balance is, by State
This screenshot shows the usage of my Count of Location and Count of State measures.
THe count of location measure works as intended but as you can see, the Count of State measure returns all available states since the higher level (upstream) table is not being filtered by the product in scope.
Any insight into how to approach this in DAX would be greatly appreciated.
Add CALCULATE to your measure:
Count of State =
CALCULATE(
COUNTROWS(
DISTINCT(locations[STATE])
)
)
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.']