I am a bit stuck with a specific case in Power BI. Let's say that we have two tables. The first one contains the product ID and the product name, and the second one contains the product ID and a specific budget.
I want to create a piechart showing the topN + group others. I have made a dax formula which works for data in a single table, but not on two.
Here is the formula :
ProductTop =
VAR rankSiteImpressions = RANKX(ALL(Piechart); [Impressions ];;DESC)
return
IF(rankSiteImpressions<=3;Piechart[Site];"Others")
How can I apply this on data from two tables to get the top products by budget?
Many thanks,
Rémi
Related
I'd like to answer a simple question: What is the avarage age of persons that own cars of specific colors ? ( Using Penatho BI, Yellowfin BI, MariaDB)
To do that the following model was designed.
One fact table "person_fact" containing the columns:
id, name and age.
And a dimension table "auto_dim" containing the columns:
id ( foreign key to person_fact table), car_type, color and hp.
As we see one person can own more than one car!
The problem is that in some filter scenarios, the persons that own several cars are counted multiple times, where they shouldn't.
For instance, trying to calcualte the avarage age of persons that own a "Black" or a "Red" car leads to a wrong result !!!
The SQL query that is generated by Pentaho BI is the following:
select
avg(`person_fact`.`age`) as `m0`
from `auto_dim` as `auto_dim`,
`person_fact` as `person_fact`
where `person_fact`.`id` = `auto_dim`.`id`
and `auto_dim`.`color` in ('Black', 'Red');
The same problem occurs using Yellowfin BI. The SQL query generated by Yellowfin BI:
SELECT DISTINCT AVG(`PERSON_FACT`.`age`)
FROM `person_fact` AS `PERSON_FACT`
INNER JOIN `auto_dim` AS `AUTO_DIM`
ON (`PERSON_FACT`.`id` = `AUTO_DIM`.`id`)
WHERE (`AUTO_DIM`.`color` IN ('Black', 'Red'))
The correct answer is 28.25 !
NOTE: Calculating the avg age with excel yields the right answer using a DAX expression!!
Question:
Is there any possibility to use something like DAX expression for Pentaho BI/Yellowfin BI to get right avg ?
Should i use a another model to fix the problem ?
Thanks in advance !!
Normally in Tableau to calculate % I create a measure and use the below logic;
SUM ([MEASURE_1])/ SUM([MEASURE_2])
However i am trying to get the % when using a measure and an already aggregated measure and I'm getting the below error;
Argument to SUM (an aggregate function is already an aggregation, and cannot be further aggregated.
My percentage is to calculated the % difference between a policy count from table 1 which is a measure. and measure 2 which I had to create to get the count of policies from table 2 as follows; Count([Policy]). I'm using SQL Server database.
Any ideas how i can resolve this issue?
Thanks!
Measure 1 is a count from table 1, the data looks like the following;
Measure 2 is from table 2, I am creating a count in tableau of the policy number, the data looks like the below;
The 2 tables join on agent number
Table 1 structure;
[UNIQUEPOL_CNT]
,[UNIQUEAGT_CNT]
,[VECHICLE_TXT]
,[VEHICLE_DESC]
,[VEHICLE_CD]
,[CODE_DESC]
,[POLICY_ID]
,[POLICY_NBR]
,[STATE_CD]
,[AGENT_NBR]
,[AGENT_NM]
,[PROP_ID]
,[WRITTEN_DT]
,[PURCHASE_DT]
,[SUSP_IND]
,[SUSPEND_DT]
,[BIND_ID]
,[INSURED_NM]
,[CHANGEDBY_ID]
table 2 structure;
[REPORT_DT]
,[AGENT_NBR]
,[TRR_TOTALPIF_CNT]
,[TRR_TOTALPON_CNT]
,[TRR_TOTALREV_CNT]
,[TRR_TOTALERR_CNT]
This is the invalid output...
UPDATED
I created two datasets to demonstrate you a solution
dataset1
dataset 2
Connecting both datasets in Tableau.
I built a view in tableau as (Note policies field blue color as it has been converted to dimension)
Now calculate a field as
ATTR({FIXED [Agent code]: count([Policy no])}/[Policies])
Adding this to viz gives me
wherein desired percentages are displayed.
Note- since the tables have one-to-many relationships fixed statement in respect of measure on lesser side of relationship will also result in same result.
ATTR({FIXED [Agent code]: count([Policy no])}/
{FIXED [Agent code]: AVG([Policies])})
I have a key column in two many to many related table and sample representation of data is -
(attaching sample version of the table to get the point across as there are other numerous columns not contributing to this visual)
table 1 -
table 2 -
I am making a line graph with date on x axis and the value1 and value 2 on y-axis. The value1 is true for all dates. It is basically a standard target value. Now I want all the value1 summed up to show in my visual as value1 and not just the ones for which I have data on those dates. To explain it better I want 1717 on the graph as well like the total in the table in the following image -
visual -
Is there a way to do this in power BI? I tried to make a shared dimension of all unique key as a separate table and connecting both the tables to that table but there is no change in visual due to that.
You can follow these below steps to achieve your required output-
Step-1 Create a custom column in your *table 1 as below-
value_1_sum =
CALCULATE(
SUM(table_2[value1]),
ALL(table_2)
)
Step-2 Configure your line chart as below. Remember, the aggregation for new custom column will be Average as shown in the image
And here below is the final output-
Additional Reference Here below is list of options you will get after right click on the measure name-
I'm working on a SSAS cube to allow user to analyze some sales.
So, I created a fact table to record all sales and few dimensions to browse inside data (category / location & store, etc...).
This is a example of the fact table output (from SQL Server Management Studio) :
When I browse my cube, I can review all sales including date, quantity, etc.
However, when I add some fields like the "unit price" or the "unit cost", it returns me a strange result probably due to an aggregate behavior.
It seems it return the sum of all matching rows (aggregateFunction property).
How to simply display the unit price of a sale without apply any calculation to the unit price column. The None value for the AttributeFunction display BLANK/NULL.
If your unitCost and unitPrice are the same for each product (I mean unitCost can be only 77.6 for product_id = 2), you can just use average (or even emulate average by SUM/COUNT) - but only for product dimension on axis!
Another dimensions will show real average values.
Maybe it's better to use this 'static' fields like attribute properties in 'Product' dimension? But you still need to add some logic to choose one value for several (or all) product members selected.
I have combined two datas which are price 2013 and volume 2013 to create one pivot table. But how can I find revenue (Volume multiply price) by using pivot table? Please help. Thanks. My column field there included Price from data 1 and volume from data 2.
Switch one of the fields to Σ Values (Volume would seem to be the more sensible) and add a Calculated Field (PivotTable Tools, Options > Tools - Formulas) say Named: Revenue and with Formula: Volume*Price.
However depending upon your version of Excel and your data, you may receive incorrect results (eg in the GT row for revenue).