PowerBI Creating New Table using values in other tables - powerbi

I have multiple data tables in a Power BI report and am hoping to create a new summarized table with new column and selected columns and rows from other data tables. Each data tables are quite large with different data elements so it's difficult to append the tables together to form one big table. Below is a simplified version just to illustrate the issue and what i wanted to achieve:
ID 1 Name is Orange
ID 2 Name is Apple
The last column: Sum Value (Agg.) in each table are Measures.
The result table I am trying to get is like below:
So basically I wanted to use Table 1 and Table 2 to create a new summarized Table with an added column 'Item Name' replacing the 'ID' column and the 'Sum Value' column. So far I've tried the Summarize and AddColumn function but couldn't get Measure Sum Value to the table.
If anyone can help, that'd be great!!
Thankyou
Michelle

This reshaping should really be done in PQ but if you insist on DAX, here you go.
Table =
VAR a = ADDCOLUMNS(
SUMMARIZE(Orange, Orange[Sum Value (Agg.)]),
"Item Name",
"Orange"
)
VAR b = ADDCOLUMNS(
SUMMARIZE(Apple, Apple[Sum Value (Agg.)]),
"Item Name",
"Apple"
)
RETURN UNION(a,b)

Related

Linking fields on Power BI

very new to Power, so sorry for asking a silly question.
I've got one table with required skills for a particular role, and a second table with a list of users and self-assessment for each of those skills.
Table1 has a 2 columns [Question] and [Required Score]
Table2 has 3 columns: [User], [Question] and [Score]
I'm trying to write a DAX formula to use as a filter: I want to return only those users where their own score is equal to or greater than the required minimum.
My current Measure is: = Table1[Question] = Table2[Question] && Table1[Required Score] <= Table2[Score]
Ask I'm typing the formula:
the tables are not being recognised
all [fields] are underlined in red
error message "A single value for column 'Question' in table 'Table1' cannot be determined.
Table1[Question] and Table2[Question] Data type = text, Format = Text, Summarization = Don't summarize, Data Category = Uncategorized
Table1[Required Score] and Table2[Score] Data type = Fixed decimal number, Format = Decimal number, Summarization = Don't summarize, Data category = Uncategorized
Can someone please explain what I'm doing wrong and point me in the direction of a fix?
Based on your tables, I'd do the following
In your Relationships, link the Question column, in Table1 & Table2
In DAX, add a new column to Table2; the formula will be something
like: Score >= RELATED(RequiredScore) i.e. a Boolean
In your visual, filter Table2 on this new column = True

RANKX without creating a summary table

I'm a newbie in DAX and I'm trying to create a visual in Power BI that shows the top 10 customers by sales.
I tried to create a calculated column in the 'Food sales' table, but I couldn't figure out how to create the rank by client ID.
I ended up creating a summary table in the model:
Consolidation Ventes =
SUMMARIZE('Food Sales',
'Food Sales'[ID Client],
"Ventes",SUMX('Food Sales', 'Food Sales'[Quantité]*'Food Sales'[Prix de vente])
)
and adding the rank calculated column like that:
Rank = RANKX('Consolidation Ventes', 'Consolidation Ventes'[Ventes],,DESC,Dense)
I obtained what I was looking for:
But I'm pretty sure there's a better way to do it, without creating an extra table in the model.
I tried creating a measure instead, but it always returned "1" and I couldn't understand why...
Is there a better way to achieve the same result?
Is there a way to create a measure instead of a calculated column, to create dynamic ranks in order to slice the with more than one column (like for example, customer name and product type)?
I hope this helps:
#Orders := COUNTROWS(Sales)
SalesAmount := SUMX(Sales,Sales[Quantity]*Sales[Price])
TopN :=
COUNTROWS(INTERSECT(
CALCULATETABLE(
TOPN(5,VALUES(Customers[Name]),[SalesAmount],DESC),
ALL(Customers)
),
CALCULATETABLE(VALUES(Customers[Name]))
))
You add the TopN measure to "Filters on this visual" and define the filter condition to "TopN is 1".

Add column with hardcoded values in PowerBI

It's probably extremely simple but I can't find an answer. I have created a new column and I would like to use the DAX syntax to fill the column with hardcoded values.
I can write this: Column = 10 and I will get a column of 10s but let's say my table has 3 rows and I would like to insert a column with [10, 17, 155]. How can I do that?
Try using DATATABLE function
Table = DATATABLE("Column Name",INTEGER,{{10},{17},{155}})
You can also put more columns with their own data if you want to, check this
https://learn.microsoft.com/en-us/dax/datatable-function
Assuming your table has a primary key column, say, ID, you could create a new table with just the column you want to manually input.
ID Value
---------
1 10
2 17
3 155
You can create this table either through the Enter Data button or create it using the DAX DATATABLE function as #Deltapimol suggests.
Once you have this table you can create a relationship to your existing table in the data model at which point you can either use this new table in your report to get the values you need or if you really need them in the existing table for some reason, you can pull them over using the RELATED function in a calculated column.
Table1 = GENERATESERIES(1, 3)
Table2 = DATATABLE(
"ID", INTEGER,
"Value" INTEGER,
{{1, 10},{2, 17},{3, 155}}
)
Now you can create a relationship from Table1 to Table2[ID] and then define a calculated column on Table1 as follows:
ValueFromTable2 = RELATED(Table2[Value])
If you don't want to create a relationship, then you could use the LOOKUPVALUE function instead in a calculated column on Table11.

Calculated Column based on other table. Direct Query sql

I have 2 tables sourced by direct query to sql.
Table1 contains 3 columns "Fruit", "Number", and "Date".
Table2 contains 2 columns "Country", and "Fruit".
Table2 is linked to Table1 with a 1->*(Many) link from Table2[Fruit] to Table1[Fruit].
I want to create a new column in Table2, containing the average of "Number" for a specified range of dates.
Any ideas of how this can be done?
Add a measure like AverageNumber = SUM(Table1[Number])/COUNT(Table1[Date]). The date range comes automatically from your filters/slicers, and the average will show correctly for a particular fruit due to the relationship you have added.

Calculated Column to get average from values in another table in PowerBI

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!!