Linking fields on Power BI - powerbi

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

Related

PowerBI Creating New Table using values in other tables

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)

Summarizing numbers over Distinct values in DAX Power BI

I am having trouble receiving correct result when trying to sum numbers over Distinct values (in DAX Power BI)
I have the following table - Tbl_Eposode:
I expect to have total numbers of [Episode] = 12
But I keep having SUM of [Episode] = 36.
My code just summarizes all Episode values instead only summarizing unique Episodes
(by EpisodeID, ProgramID))
This is my code:
# Pre Homeless Days = CALCULATE(SUM('Tbl_Episode'[Episode]),
ALLEXCEPT('Tbl_Episode','Tbl_Episode'[EpisodeID],
'Tbl_Episode'[ProgramID],
'Tbl_Episode'[ClientID]))
Please Help!
As David Brownse says, this really needs remodelling. However, if you are adamant that this is the way to go then:
# Pre Homeless Days =
SUMX( SUMMARIZE(Tbl_Episode, Tbl_Episode[EpisodeID], Tbl_Episode[ProgramID], Tbl_Episode[ClientID],Tbl_Episode[Episode]), Tbl_Episode[Episode])
You can just group the table in Power Query by EpisodeID, ClientID and ProgramID and compute the maximum of Episode and compute the sumation.
= Table.Group(#"Reordered Columns", {"EpisodeID", "ClientID", "ProgramID"}, {{"Max_Episode", each List.Max([Episode]), type nullable number}})
DAX:
Pre Homeless Days 2 = SUM(Max_Episode[Max_Episode])
Output in Table:
New Table "Max_Episode" created in Fields Pane:

Get sum of column values for specific rows only | Get sum of sales for each country

I am super new to power bi and Dax and i need to create a calculated column in which i have the total sales for each country respectively.
Here is a screenshot with an oversimplified scenario but if i can do it for this data i can do it in my actual project since the concept is the same.
The column TotalSalesPerCountry is the calculated column.
And here is what the column should look like if it worked. (Colors are just for visual representation)
Basically everywhere you see the same country you should see the same TotalSalesPerCountry values which are calculated by sum-ing the Sales for those countries over the years.
Another DAX function:
= CALCULATE(SUM(CountrySales[Sales]), FILTER(CountrySales, CountrySales[Country] = EARLIER (CountrySales[Country])))
This is simple to do in DAX. Add the column:
TotalSalesPerCountry =
var curCountry = yourTable[Country]
return CALCULATE(SUM(Sales), FILTER(yourTable, curCountry = yourTable[Country]))
Explanation:
For each row in the table, get the country. Filter yourTable on the curCountry and SUM this together).

Power BI slicer OR condition

The interaction between two slicers in Power BI gives me output with AND condition.
Example: If I selected the year 2020 and company ABC, the output would be all the data from company ABC in the year 2020.
But I want the two slicers to work with OR condition.
I have used this Dax
Include = (MAX(Table1[Column1]) = SELECTEDVALUE(Col1[Column1])) +
(MAX(Table1[Column2]) = SELECTEDVALUE(Col2[Column2]))
But the problem with above Dax I have not selected anything in slicer ( ALL by default) it is showing me a blank visual. What am I doing wrong?
let me guess you have a table "or_slicer_main_table" with Year, Company and some other columns. Now create 2 new table where the first one will contain the distinct list of Year from table "or_slicer_main_table" and the second one will contain distinct Company list from that same table.
New custom Table 1:
or_slicer_year_list =
SELECTCOLUMNS(
'or_slicer_main_table',
"YEAR", 'or_slicer_main_table'[year]
)
New custom Table 2:
or_slicer_company_list =
SELECTCOLUMNS(
'or_slicer_main_table',
"company", 'or_slicer_main_table'[company]
)
Do not establish any relation between those 3 tables.
Step-1: Create Year slicer using the newly created "or_slicer_year_list" table.
Step-2: Create Company slicer using the newly created "or_slicer_company_list" table.
Step-3: Create these following 5 measures in your table "or_slicer_main_table"
1.
year_current_row = max('or_slicer_main_table'[year])
2.
year_selected_in_slicer = SELECTEDVALUE(or_slicer_year_list[YEAR])
3.
company_current_row = max('or_slicer_main_table'[company])
4.
company_selected_in_slicer = SELECTEDVALUE(or_slicer_company_list[company])
5.
show_hide =
if(
[year_selected_in_slicer] = [year_current_row]
|| [company_selected_in_slicer] = [company_current_row],
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "or_slicer_main_table"
Final Step: Now just add a visual level filter for the measure "show_hide" and set value will show only when "show_hide = 1".
The final output will be something like below image-
Can you try using "IN VALUES" instead of "SELECTEDVALUE"
So your DAX should be
Include = (MAX(Table1[Column1]) IN VALUES (Col1[Column1])) +
(MAX(Table1[Column2]) IN VALUES (Col2[Column2]))
SELECTEDVALUE function returns the result only if single value is selected in slicer in case of multiple selection it will return Blank(). Thats in the case when nothing is selected (which is similar to all selected) has multiple values in set and so SELECTEDVALUE fucntion will return Blank(). This can be handled by using "IN VALUES" function which can return a set of all selected values.

How to find the sum of values present in one table and missing in other table

I am trying to find the sum of the values corresponding to a key that is present in Table 1 but not in Table 2.
These tables have been created based on some filters and represent the values on 2 different dates.
The two different dates are chosen from 2 different date tables which have an inactive relationship, specially created for this purpose.
I want to create a measure that finds out the sum.
Below is the syntax I have used:
Difference =
VAR
Table1 = CALCULATETABLE(VALUES('TableA'[Id]), 'TableA'[Type] = "ABC", ALL('Date'), USERELATIONSHIP('Date'[As of Date], Previous_Date[Previous_Date]),USERELATIONSHIP('Date'[As of Date], 'TableA'[As of Date]))
VAR
Table2 = CALCULATETABLE(VALUES('TableA'[Id]), 'TableA'[Type] = "ABC", USERELATIONSHIP('Date'[As of Date], 'TableA'[As of Date]))
RETURN
IF(AND(VALUES('TableA'[Id]) IN Table1 , NOT(VALUES('TableA'[Id])) IN Table2),
CALCULATE(SUM('TableA'[Values])),0)
It is error-free. However, when I drop the measure on a KPI visual, I am getting the following message:
Please tell me what is wrong with the syntax. Also, please let me know if there is any better code that can be written.
Kindly help.
The reason you are getting an error is that it expects a single value for x when you write x IN Table1 but using the VALUES function can return a list rather than a single value.
I'd try something more like this after the RETURN:
SUMX (
'TableA',
IF ( 'TableA'[Id] IN Table1 && NOT ( 'TableA'[Id] IN Table2 ), 'TableA'[Value] )
)
This iterates through each row of TableA and checks if the Id value in each row is in the tables you calculated. If the condition is met, it adds the Value. Otherwise IF returns a blank (which is treated the same as 0 in a sum) since there is no third argument.