I have 2 tables.
I am joining both of them via a 1 to many relationship.
The KPI I want to use is in Table_1, but I'm grouping it based on a column in Table_2.
When I throw the measure onto PowerBI, it gives the same value for all rows.
I created the measure like this:
sales_in_cents := (sum(Table_1[Sales]) * 100)
When I group the data using a column from Table_2, it gives me the same value for each row in Table_2.
Why is this?
How do I fix it?
Edit #1
It's similar to this, but I do have a relationship.
Edit #2:
Table_1 has a 1 to many relationship with Table_2 and cross filter direction is set to single.
Edit #3:
I think I need to use some sort of combination of the LookUpValue and/or RelatedValue Function.
Table_1 has a 1 to many relationship with Table_2 and cross filter direction is set to single.
That means that Table_1 can filter Table_2, but not the other way round. This is why you get repeated values when using a column from Table_2 and a measure based on the Table_1, the filter context doesn't propagate
How to solve it
Measure with TREATAS:
https://www.sqlbi.com/articles/propagate-filters-using-treatas-in-dax/
Calculated column in Table_2 that would use RELATED (as each row in Table_2 has a single, related row in Table_1, for referencing the many side you need to use RELATEDTABLE)
changing the relationship to bidirectional - it can create ambiguity, so I don't recommend it
This model seems a bit peculiar, is it something like a Table_1 is monthly budgets, while Table_2 is daily sales? In general star schema is recommended in the tabular models, it makes life much easier if you can use that schema
Related
I need to create a kind of dynamic DAX view based on another DAX table.
First Table
Year, Category, Sub-category, Sales, Sub-Category Weight
I need to do a intermediary step different calculation for Sales on another table that looks at the above table however I can't work out how to do do it. I have a slicer populated with a subcategory dimension on the tab so every time I make a change I need the below table to reflect the chosen sub category but without it being in the table.
Second Table
Year, Category, Sub-category, Sales, Category Weight filtered by Sub-Category
I have tried the following functions:
Summarize
SummarizeColumns
CalculateTable
(think there are more)
I have tried to use each with a filter based on the slicer but I can't get it to work.
I'm new to Power BI. I have 2 tables ('patient_info' and 'rating_table') which are related to each other 1:1 by the "id" key. I created another summary table ('rating_by_doctor') which groups the ratings among each doctor and calculate the mode for each of them. The DAX expression I used to get the summary table are as follow:
rating_by_doctor =
SUMMARIZE(
rating_table,
patient_info[doctor],
"mode",
MINX(TOPN(1,ADDCOLUMNS(VALUES(rating_table[rating]),"Frequency",CALCULATE(COUNT(rating_table[rating]))),[Frequency],DESC),rating_table[rating])
)
The tables look like this
However, when I try to add this table into a visualization, and apply a filter/slicer on it (eg: the [gender] column in 'patient_info'), it has no effect to the summary table at all. I want the visualization of the summary table reflects the change of the underlying aggregated calculation based on the current filter/slice, may I know how can I achieve this please?
I have 2 tables in PowerBI.
Table 1:
Table 2:
I have the sales target for each month in Table 1 and also the actual sales that I achieved in Table 2. May I know how should I create another column in Table 1 where it sum all the sales from Table 2 based on respective months? The expected output will be something like this:
Expected output:
Any help or advise will be greatly appreciated!
Here's one potential solution:
Summarize table two so that it groups the total sales by month. You can do this by grouping on the month in power query, or using a dax function like SUMMARIZE.
Create your new column in table 1 using the LOOKUPVALUE function. It will look something like this LOOKUPVALUE(Total Sales, Date, Month & Yrs).
Make a relationship between Table 1 and Table 2 using "Month & Yrs" and "Date".
Then it's just a matter of adding a table with "Month & Yrs" as rows, and "Sales Target" and "Sales" as values. You can then just rename if you want.
I'd recommend using a calendar dimension as a general rule. Much easier to make relationships, add columns etc.
I have data from multiple countries on a monthly basis. Since the updates are not regular, I want to set up filter to visuals, so they would show the last month for which I have data from all the countries. I have data from each country loaded into a separate dataset, which then are merged into one big. Is there an easy way to place such filter? I managed to use "LASTDATE" function in each of country sets to find which date is last, but if I try to filter with that measure, I simply get nothing in a result. Thanks!
Well, this feels a little clunky to me but I believe it will work for you. There are two steps. The first is to create a summary table that reads through your data and counts the number of distinct countries that you have in each month. This will be a new table in your model, so go into the modeling tab, click 'New Table' and add this DAX. Obviously, correct for your table and column names.
SUMMARIZED_ROWS = SUMMARIZE(
'Table1'
,Table1[Month]
,"CountOfCountries"
,DISTINCTCOUNT(Table1[Country])
)
Now add a measure to the table (or anywhere) like this:
MonthWithMostCountries = CALCULATE(
LASTNONBLANK(SUMMARIZED_ROWS[Month], 1 )
, FILTER(SUMMARIZED_ROWS, SUMMARIZED_ROWS[CountOfCountries] = MAX(SUMMARIZED_ROWS[CountOfCountries]) ) )
This is going to give you the month where you have the most distinct countries in your data. You'll want to look at it in a card or similarly isolated visual as it is a measure and can be affected by filter context.
So, on the left is my mock data - 3 countries, 3 months each with a 1 month stagger. On the right you see the result of the Summarize table. Then the measure showing the final result.
Hope it helps.
This might be very basic but I am new to PowerBI.
How do I get average of values for unique ID into another table.
For eg. My Table 1 has multiple ID values. I have created another table for unique ID which I am planning to used to join other table.
I want a calculated column in table 2 which will give me average value of respective ID from table 1.
How do I get the calculated column like shown below
In stead of creating a new table with the averages per ID and then joining on that, you could also do it directly with a calculated column using the following DAX expression:
Average by ID = CALCULATE(AVERAGE('Table 1'[Values]),ALLEXCEPT('Table 1','Table 1'[ID]))
Not exactly what you asked for, but maybe it's useful anyway.
How's it going?
The quickest way I can think of doing this would be to use
SUMMARIZECOLUMNS
You can accomplish this by creating another table based on your initial fact table like so:
Table 2 =
SUMMARIZECOLUMNS ( 'Table 1'[ID], "Avg", AVERAGE ( 'Table 1'[Values] ) )
Once this table has been created, you can create a relationship.
This will work in either SSAS or in PowerBI directly.
Hope this helps!! Have a good one!!