New to DAX.
I have a rather (from my point of view) complicated tables relationship model :
Model
It's a knowledge database in my company.
There are many "compétences" for each employee in table DONNEES. These "compétences" are categorized in the LMC table which is a bridge table between COMP & METIERS defining the "compétences" needed for a "métier".
One "competence" can be in multiple "métiers"
In table "DONNEES" I have all employees, plus standards profils for each "métier". This table defines the level (1 to 5) for each "competences".
My matrix in Power Bi works like a charm. I can sum all "competences level" for each métiers.
I've added a measure, which normalizes this sum over the sum gotten for each standard profil (this sum is "hard coded" in METIERS, not calulated)
Grade = CALCULATE(SUM(DONNEES[Niveau]); LMC)/CALCULATE(SUM(METIERS[Niveau_type]);LMC)*5
And it works (even if the "total" columnn isn't correct)
//EDIT//
With the following modifications, it works :
Grade = CALCULATE(SUM(DONNEES[Niveau]); LMC,DONNEES,METIERS)/CALCULATE(SUM(METIERS[Niveau_type]);LMC,DONNEES,METIERS)*5
(I've added all tables from my many to many relationship)
The grand total column is now ok.
//EDIT//
Now, I want to compute a the number of employee that fulffil a specific grade for each métier.
I've thought to create a binary measure that checks that :
gradefulfilled= IF(DONNEES[Grade]>4,5;1;0)
An then use the total row to have the number of employees in the company able to do that "métier"
It doesn't work. The total sticks to zero, even if the gradefulfilled binary is correct for everyone.
//EDIT//
The total does'nt stick to zero, it can be 1 if there's one employee OK, but sticks to 1 if more than one employee.
//EDIT//
You can propose either a totally different way to compute what I want (number of employees able to do a "métier" or explain to me where I made a mistake in my computations.
Hurray !
My bad. Problem seems solved.
The problem seems related to the way grand total is calculated in pivot table (the sum of the measure calulated for each line, not on the sum of each measure in the matrix)
So I've used a sumx to get a proper sum :
Nbgradefulfilled = sumX(NOMS;DONNEES[gradefulfilled])
Related
I have a database that has some values as "Date", "StopedTime", "PlannedProductionQtt" and "PlannedProductionTime". These values are sorted by equipment, as the little example below.
What I need to do is divide PlannedProductionQtt by PlannedProductionTime and then multiply by StoppedTime. After this, I want to make a graph that shows it day by day.
At first I thought it was easy, made a new measure PlannedProductionQtt/PlannedProductionTime = SUM(PlannedProductionQtt)/SUM(PlannedProductionTime) (assume it worked without the table name).
And then I did another measure Impact = SUM(StoppedTime)*PlannedProductionQtt/PlannedProductionTime.
When I plotted a clustered column chart with this measure in values and a the day for the axis, at first I thought I had nailed it, but no. The BI summed all of PlannedProductionQtt and divided by the sum of all PlannedProductionTime for the day, and multiplied by the sum of the StoppedTime of that day.
Unfortunately, this gives me wrong results. So, what I need is a measure (or some measures) that would make it equipment by equipment and the sum it by day.
I don't want to make new tables or columns for theses calculations because I actually have 32 items of equipment, 3+ years of data, more than 1 classification of StoppedTime and the databases for PlannedProduction use more than one line per day per equipment.
To make it clear I added one column as Impact to show the difference.
So, if I sum the column Impact per day, I would have for day 1,2 and 3 the results 110725, 61273 and 220833.
However, if I sum first all the PlannedProductionQtt for day 1, divide it by the sum of PlannedProductionTime of day 1 and multiply it by the sum of StoppedTime of day 1 (which is how PowerBi is calculating) I will have 146497.
I inserted the difference in the table below to make the differences clear:
As Jon suggested in a comment, here is what solved my needs:
measure_name = SUMX( source_table , DIVIDE ( source_table[PlannedProductionQtt] , source_table[PlannedProductionTime] , 0 ) ) * SUM( source_table[StoppedTime] )
You have two different types of data you want to divide there, time and int, so you would probably need to unify that. Easiest way to do it would be from the Transform data panel, selecting the column and changing its
format
The division is done fairly easily, can you try creating a new measure as follows
measure_name = CALCULATE(
DIVIDE(<source_table>[PlannedProductionQtt],
<source_table>[PlannedProductionTime],
0)
* <source_table>[StoppedTime]
)
Then it's only a matter of using it as values in a graph and the 'Date' column in x axis.
I'm new to DAX. Looking for your expertise. Looked all over the web but couldn't find a proper solution.
I have a matrix that shows several factories and it's inventories, the rows being factory and SKU. I've created a measure that's the difference between two other measures. The overall idea is: I have a inventory quantity and an orders volume. I defined a "balance" measure that's inventory - sales. That is, what is still left for sale.
Normally it works fine, but when I have a negative value in balance, things get messed up. The subtotal in the factory row sums all the numbers, including negatives, giving me a balance subtotal that is smaller than it's supposed to be. I can't count the negatives. So I've tried to solve this by defining the measure as
Balance = IF([Inventory]>[Sales],[Inventory] - [Sales],BLANK())
Now this works fine visually to display only the positive values in balance, but still sums up the negatives in the factory subtotal.
How can I make this measure to only show and sum up the positives?
I appreciate your help.
P.S.: the inventory and sales measures are basically SUM's of different tables for simplicity and understanding by my part
Matrix with measures. The columns are "Estoque" as inventory, "Embarque programado total" as sales and "Saldo Disp. Venda" as the balance
Create a measure with the below code.
Balance = CALCULATE(SUM([Inventory]) - SUM([Sales]), FILTER(Table1, [Inventory]>[Sales]))
As it turns out, I was able to find a solution through trial and error. I changed my measure to (FatoEstoque is the table that contains the inventory numbers):
Balance= CALCULATE([Inventory]-[Sales],FILTER(FatoEstoque,[Inventory]>[Sales]))
Although I'm not even sure why it works (lol), it works! So I'm not complaining. This measure only sums up the positive values, showing the correct subtotal as I needed.
Filtering the Inventory table to values where [Inventory]>[Sales] works, but adding another filter with the Sales table and the same condition don't.
Here is an image comparing the results. The new measure is called SaldVender2
I'm new to PBI Desktop & StackOverflow in general. If anyone can help me out with this situation, much appreciated.
I created this matrix table where it displays the count of male/female students in a student division (I just made up these numbers). I created a measure called 'Percentage of males' that calculates the number of male students and divide it by the total number of students in each division.
The calculation wasn't, the hard part, but the issue is when I place the measure in the values field. Instead of just wanting to show it for totals only, it appears under the female & male subcategories as well (refer to image). Does anyone know if there's a way to modify the measure so that it only affects the total?
I tried looking at some videos, but couldn't really find one for this situation.
Proportion of Males = DIVIDE(
COUNTX(
FILTER(sheet2, Sheet[M/F]="M"), Sheet2[M/F], COUNTA(Sheet2[M/F]), 0)
I have a "strange" problem in visualizing the values of the "last" year (that is the most current year with data of a full year). In the example delivered it is 2019 which holds the bookings facts. The year should be derived by a related table (LetztesVollesJahrDim) that holds a min/max date and year value for each company/entity. The DateDim table holds all dates and is configured to be the Date dimension.
The relations are shown in the graphic below.
I created a Report that should display different matrix tables with different values:
one, that shows the last full year's monthly values by Cost Center (which works correct)
one, that shows all years monthly values including an estimated value for the current year (2020) (which also works correct)
one, that could drill down to the details level of the Facts and display the figures per month (in columns) of the last full year (i.e. 2019) putting the Cost Center and other groups down the most detailed level into rows. This Matrix makes use of Calculated Measures created with Tabular Editor.
At this point I can here you say... try it without the Calculated measures and indeed I did that by simply displaying a Card that got a Visual Filter to DateDim[M]=7 to simulate the appliance of each matrix's column. Problem is the same: The Month filter of the Visual (or within the Calculated Measure) is ignored and the yearly sum is displayed (~48k) which is wrong.
As I am currently an Expert in SQL Server DBMS but not in the Architecture of Power BI's DAX Models I am not truely aware about the consequences when and why filters are removed, ignored, overwritten or added at which level of modeling.
Originally I tried to create a simple Calculated Measure that reflects the last full year of the company. That works, but its usage in the huge Matrix was impossible as it was calculating forever. That's why I created the simple table "LetztesVollesJahrDim" to hold a persisted value for each company.
The idea is simple: Create a Query that inner joins these tables and display the Sum for each month [M] like this:
Fact[Turnover] - Fact[CompanyKey] -> CompanyDim[CompanyKey] <-> LastFullYear[CompanyKey] - LastFullYear[MostCurrentYear] -> DateDim[Y] - DateDim[DateKey] -> Fact[StapleDateKey]
So, what is the Problem?
I tried a couple of DAX queries and all come up with a different wrong value.
Following three different approaches for a Calculated Measure "Sum LY":
1.
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), DATESBETWEEN(DateDim[DateKey], DATE(2019, 1, 1), DATE(2019, 12,31)))
2.
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), SAMEPERIODLASTYEAR(DateDim[DateKey]))
[
3.
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), KEEPFILTERS(DateDim[M]), USERELATIONSHIP(DateDim[J], LetztesVollesJahrDim[AktuellstesJahr]), USERELATIONSHIP(DateDim[DateKey], KontobuchungenFact[StapelDateKey]))
Filters being applied on the page/visual:
CompanyKey
DateKey >= 2018-01-01 (page filter that limits the displayed rows in yearly matrix to the last 3 ys)
Some other irrelevant keys
Visual configuration:
Relations:
Values/Rows in the LetztesVollesJahrDim table:
Calculated Measures/Table in Tabular Editor showing the calculation of the "01 Jan" column of the first Matrix, which displays correct results:
Impression of the Report:
So in summary I need a clue/DAX formula that recognizes the Monthes in each column and ideally uses the relations to the last year table trespassing the year's filter through DateDim to the Facts.
It is funny, that the upper matrix works, but not the one on the bottom. It is not possible to use the calculated measures approach of the first matrix in the last matrix because the performance would drop to > minutes calculation. So I cannot use the same approach and need a fast one.
Anybody an idea? :-)
I am working on a report that has data by month. I have created a measure that will calculate a cost per unit which divides the sum of dollars by the sum of production volume for the selected month(s):
Wtd Avg = SUM('GLData - Excel'[Amount])/SUM('GLData - Excel'[Production])
This works well and gives me the weighted average that I need per report category regardless of if I have one or multiple months selected. This actual and budget data is displayed below:
If you take time to total the actual costs you get $3.180. Where I am running into trouble is a measure to sum up to that total for a visual (This visual does not total sadly). Basically I need to sum the aggregated values that we see above. If I use the Wtd Avg measure I get the average for the total data set, or .53. I have attempted another measure, but am not coming up with the correct answer:
Total Per Unit Cost = sumX('GLData - Excel','GLData - Excel'[Wtd Avg])/DISTINCTCOUNT('GLData - Excel'[Date])
We see here I return $3.186. It is close, but it is not aggregating the right way to get exactly the $3.180:
My Total Per Unit Cost formula is off. Really I am simply interested in a measure to sum the post aggregated Wtd Avg measure we see in the first graph and total to $3.180 in this example.
Here is my data table:
As you probably know already, this is happening because measures are dynamic - if you are not grouping by a dimension, they will compute based on the overall table. What you want to do is to force a grouping on your categories, and then compute the sum of the measure for each category.
There are 2 ways to do this. One way is to create a new table in Power BI (Modeling tab -> New Table), and then use a SUMMARIZE() calculation similar to this one to define that table:
SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg])
Unfortunately I do not know your exact column names, so you will need to adjust this calculation to your context. Once your new table is created, you can use the values from that table to create your aggregate visual - in order to get the slicers to work, you may need to join this new table to your original table through the "Manage Relationships" option.
The second way to do this is via the same calculation, but without having to create a new table. This may be less of a hassle. Create a measure like this:
SUMX(SUMMARIZE('GLData - Excel',[Category],[Month],[Actual/Budget],"Wtd Avg",[Wtd Avg]),[Wtd Avg])
If this does not solve your issue, go ahead and show me a screenshot of your table and I may be able to help further.