I'm sure the nature of my question will reveal I am a rookie at PowerBI. -- so, please, don't hesitate to write like you're writing to a 10 year old. I have a table with several records per person (sorted by person). Each record has a Weight. I want my PowerBi report to display only one record per person with the sum of all that person's weights. There might be a wrinkle in that the weight is in a different table (two tables away via two relationships). Since I am in learn mode, don't mind if solution comes in progressively more difficult steps (as the weight table gets further away from the people table).
Data model:
- 'PersonTable' related to 'TestTable' by 'Name'
- 'TestTable' related to 'WeightTable' by 'Test'
I have tried creating a new column (not measure) in the PersonTable (and I have tried putting a new column in the TestTable) and then using various formulas to try to sum the weights in the WeightsTable - to no avail. The summed weights always come back including the sum of all possible weights in the WeightsTable.
Here is some contrived test data and expected results....
* Name Test Weight
* ------ ----- ------
* Dave TestA 3
* Dave TestC 5
* Dave TestE 7
* Harold TestA 3
* Harold TestB 4
* Jack TestD 6
* Jack TestE 7
Desired Results:
* Dave 15
* Harold 7
* Jack 13
I have concocted a "codeless solution" using the groupby feature. I am dissatisfied with it though because I believe this approach will not allow me to "drilldown" through one of the aggregated records produced to see the detailed records that were grouped. That will be the subject of my next question.
Here is the "solution"...
Use the "Query Editor" to modify the 'TestTable'.
Merge the query for the 'WeightTable' into the query for the 'TestTable' keeping only the weight column from the merged in table.
Duplicate the new column. (I thought I would want two columns so that I could keep the un-grouped weights for detail reporting, but this has not been the case yet.
Push the "GroupBy" button on the ribbon for the "Home" tab and fill out form as follows...
Radio Button - Basic
Group by: "Name"
New Column Name: "Sum of Weights"
Operation: "Sum"
Column: "Weight-Copy"
This generated the values I am looking for but removed the columns holding the detail data in the 'TestTable' which I will need for later (possibly drillthrough) reporting. So I continue to seek a better solution...
I believe you've chosen a proper solution, up until step 4. Remove that step and load the joined dataset into the data model.
Then, just drag and drop the desired columns onto the canvas (weight and name). PowerBI will automatically sum the weights and then group that by name, producing your desired output.
Related
I am relatively new to PowerBI and struggling to accomplish the following task.
I have in total 3 Tables. 2 Tables are available and the 3rd is the outcome I am interested in.
Table 1 is a lookup table with yearly values for each option of a certain property.
Table 2 is a user input table containing the project list with a property that can be equal to one of the options in Table 1.
I am mostly interested in Mapping the projects with their yearly development based on one property. The outcome is represented in Table 3.
At the end of the day, I would like to plot the Sum across all projects against the year column (The 2 columns in red).
I hope someone can help here in finding the appropriate DAX logic. Thanks in advance!
You can bring the tables into a Power BI model, and from the modeling tab you can create relationships to accomplish this. Let me know if this is helpful.
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 have a dropdown in Power BI that contains different project name such as Project One, Two, Three. I have included one formula to bring forecast value which is:
Forecast = Chase * Target%
I have created one measure that calculates forecast. The dataset contains weekly based data for Chase and Target %. For example week 1 (Jan 01-Jan 08) Chase will be 30 and target % as 10 hence the forecast for Week 1 is 3 (30*10%)
When I select one project from dropdown list e.g. "Project One" I see the forecast value populating correctly. Same goes if I select only one project from dropdown list .
The issue arises when I select multiple projects and then the forecast value brings the maximum value instead of bringing summation to the values of all weeks of all projects.
Question: What exactly is causing the issue?
Now I understand your requirement from your comments. You can achieve this through 2 step as explained below-
Step-1: Create a custom column in your data source as below-
row_level_forecast = finetarget[chase]/100.00 * finetarget[target]
Step-2: Create the final Measure as below-
forecast = sum(finetarget[row_level_forecast])
Now, use measure "forecast" in the report. This should give you the desired output.
ISSUE-2: From your comments
If I understand correct, you are talking about a case where you are concern about values in columns I marked red in the below picture-
If I am correct with my understanding, you wants to fill week-3 values for Project-1 with 80/70 and for Project-2 100/90. If this is ok, just follow these following steps.
Step-1: Go to EDIT mode clicking "Transform Data" option and select the table you wants to adjust data.
Step-2: Sort your data first for project_name (ascending) then week (ascending). The output will be also as shown in the above image.
Step-3: Select column "chase" in the table and click Fill>>Down option.
Step-4: Repeat step 3 for column"target" as well.
The final output should be as below. Just move back to main report by clicking "Close and Apply". Data should be now as expected in your report.
When you display the forecast, put it in a grid and add the project column, the week column (e.g. Week 1) and the forecast measure. When you select your multiple projects the grid will show each of those along with the calculated measure. If this does not work, there is something wrong with your measure and you should add your measure calculation script to your question.
The measure should be simple, something like:
Forecast = SUM(YourTable[Chase]) * AVERAGE(YourTable[Target%])
How to rank based on a field where the value is the same. There is some more ranking applied here and this scenario need to be addressed as well as I can not rank again by Sales field. Instead, I need to say:
If Unit is the same on the list of territories, rank based on Sales.
Example:
Terr Sales Unit Should look like : Terr Sales Unit
---- ------ ----- -----------------------
Boston 1 5 Maine 10 5
Maine 10 5 Boston 1 5
Often a mathematical approach works well for this. First, without wanting to patronise, it's possible to use a discrete (blue) measure to sort data. Place the sorting pill to the far left on the Rows and the table will sort according to this pill.
Ok, so the formula. Without knowing how large the Sales figure can go, you want to create a calculation that would give the highest value to that you want to appear top.
For example perhaps multiple Unit by 1,000,000 and add Sales. Just make sure the Units are multiplied by a number large enough to make Sales inconsequential.
This field may work, depending how large the Sales figure can go:
[SortField] = (SUM([Unit])*1000000 + SUM([Sales])) * -1
Put the field to Rows, convert to Discrete, then place to the far left. If the sorting is correct hide the field header.
It multiplies by -1 to sort descending.
I'm trying to create an "opportunity" calculation model, but the output results that I'm getting are not accurate. Sample problem would be McDonald's and Burger King who sell food in various regions, some regions have both BK and McD in the area and they both sell similar food types, but some have both in the area however they can't fulfill the same order type (an example would be zip code 10049 where BK and McD both exist, but McD sells burgers and BK sells salads; so BK can cover the area, but can't fulfill potential customer want.)
In the example spreadsheet, there are three tabs, first with McD sales, second with BK sales, and the third reconciles the naming convention between McD's and BK's orders.
I started by connecting the tables with relationships. I figured I need to connect McD to BK by Zip, then McD to Crossreference. Due to many-to-many relationship limitations in PBI, I'm forced to create lookup tables with unique values for zips, and order names. Looks a bit messy, but does the job. The problem is that I can look up the zip code connections, but not the sales for the potential orders.
Relationships:
This is a clear example of how things don't work. Zip code 10048 sums up McD's sales and displays it for each BK order type. The expected output would be $5 for angus and $3 for onion soup, $8 in total.
If I try to connect crossreference BK order names to BK orders, then I get an ambiguity error.
Spreadsheet data file:
https://docs.google.com/spreadsheets/d/1WM9OD7voApax7uNJ6_bJk75zfj9FQN9tSf2jU1hXl7c/edit?usp=sharing
Excel and Power BI files: https://drive.google.com/drive/folders/1hOdP5ZglHcqo_dk2GMlXr6Xmc5Ywm6nj?usp=sharing
I don't think you'll be able to do this exactly how you want to. It would basically equivalent to creating multiple relationships between two tables. Power BI doesn't let you do that.
There are some workarounds though. For example, you can pull over the McD[order] values into your BK table using a calculated column:
MDorder = MAXX(FILTER(Crossreference, Crossreference[BK] = BK[order]), Crossreference[McD])
This will allow you to pull across the price from the McD table using a lookup or similar max type function:
Price = LOOKUPVALUE(McD[price], McD[order], BK[McD Order], McD[Zip], BK[Zip])
or
Price = MAXX(FILTER(McD, McD[Zip] = BK[Zip] && McD[order] = BK[McD Order]), McD[price])
Once you do that, you can work entirely on the BK table.
Note that some price rows will have nulls since there was no corresponding McD row with matching zip and order. (I suppose you could take the median price of those orders over the zip codes they do exist in and plug that in those cases...) If the price is uniform across zip codes, then this can be made simpler.
Also, notice that when you put the price into a table and use an implicit measure on it, it will likely default to a sum and you'll get $6 for 10048 and angus since you have duplicate rows. Switching to max will get you the $3 if that's what you prefer.
This type of merging is also possible to do in the query editor, but I couldn't play with that on the pbix you included since I don't have access to the data source on your C: drive.