I have a DAX variable that contains a table. How can I reference a particular column in that variable?
For example, in the below command, the EVALUATE returns an error. But it works if I replace table1 with FactInternetSales (which is the name of the table which contains that column)
define var table1=FactResellerSales
EVALUATE ROW("a",COUNTBLANK(table1[SalesAmount]))
You can reference them only using functions that iterate.
For example,
DEFINE
VAR _TABLE1 = FactResellerSales
EVALUATE
{COUNTX(_TABLE1 , _TABLE1 [SalesAmount)}
Other example of iterator functions are sumx, filter.
Related
Can someone explain how the first filter statement is different from second in DAX?
FILTER(Table, Table[Column] = "some text")
FILTER(VALUES(Table[Column]), (Table[Column] = "some text"))
The FILTER function is a table function, meaning it will return a table. In the case of your second example, it is likely that you will get a scalar value (a single value) because you are filtering a table (of one column of unique values) by a single value. In the first FILTER instance, however, you will be returning an entire table of the first argument, which has only been filtered by the conditional in the second argument. For reference, I have used the sample data built within the Power BI Desktop version to show you the key differences.
From your first FILTER example
FILTER( financials, financials[Country] = "Germany" )
Output
From your second FILTER example:
FILTER( VALUES( financials[Country] ), financials[Country] = "Germany" )
-- The extra parantheses around the second argument are not necessary...
Output
Therefore, the main functional difference is in the output. What are you wanting to return? An entire table or a specific value(s) of a column(s)?
I have a star schema model.
I have 2 tables, they look like this.
D_COURSES
Course_ID
Course_Name
Subject_Order
F_STUDENTCOURSES
COURSE_ID
POINTS_CAT_A
POINTS_CAT_B
I want to take the F_STUDENTCOURSES[COURSE_ID] value and look up the Subject_Order value in the D_COURSES table. If that value is 1, I want to sum the POINTS_CAT_A or POINTS_CAT_B value, for a divide function.
This is the DAX funciton I am using:
divide(
calculate(sum(F_STUDENTCOURSE[POINTS_CAT_A]),LOOKUPVALUE(D_COURSES[SUBJECT_ORDER],F_STUDENTCOURSE[COURSE_ID],1)),
calculate(sum(F_STUDENTCOURSE[POINTS_CAT_B]),LOOKUPVALUE(D_COURSES[SUBJECT_ORDER],F_STUDENTCOURSE[COURSE_ID],1)), "")
The error message I am getting is this:
Function LOOKUPVALUE expects a column reference as argument number 2.
What am I doing wrong?
Lookupvalue works this way lookupvalue(column to return, column to search in, value to search for from the column). In your case it would be lookupvalue(d[subject],d[course_id],f[course_id])....returns the d_subject by lookingup f_course_id values in d_course_id column.
I don't think Lookupvalue works inside calculate. Can you please try the following
MEASURE=
VAR _1 = Calculate(sum([catA]),Filter (values(d[sub_order]), d[sub_order]=1))
VAR _2 = Calculate(sum([catB]),Filter (values(d[sub_order]), d[sub_order]=1))
VAR _3 = DIVIDE (_1,_2)
RETURN _3
Assuming there is relationship it sums up catA and catB when suborder=1 and then divides
I have a table visual in PowerBI that summarizes work hours by employee. The first column shows the employee name.
When training managers on how to use it I want to anonymize by showing employee numbers instead of names.
I tried adding a what-if parameter Anonymous with values 0 and 1 and use IF() in the DAX of a calculated column but it is not working. It ignores the parameter value.
Person = IF(Anonym[Anonym value] = 0; Time[Name]; Time[Empno])
will always show Name.
Person = IF(Anonym[Anonym value] = 1; Time[Name]; Time[Empno])
will always show Empno.
Another option if you really need to use a column and needs it to be "dynamic" is to use a PowerQuery parameter and add a new column based on it and then create your conditional. The downside of this is that you will have to refresh your query everytime you want to change the parameter
I have the following query in M:
= Table.Combine({
Table.Distinct(Table.SelectColumns(Tab1,{"item"})),
Table.Distinct(Table.SelectColumns(Tab2,{"Column1"}))
})
Is it possible to get it working without prior changing column names?
I want to get something similar to SQL syntax:
select item from Tab1 union all
select Column1 from Tab2
If you need just one column from each table then you may use this code:
= Table.FromList(List.Distinct(Tab1[item])
& List.Distinct(Tab2[Column1]))
If you use M (like in your example or the append query option) the columns names must be the same otherwise it wont work.
But it works in DAX with the command
=UNION(Table1; Table2)
https://learn.microsoft.com/en-us/dax/union-function-dax
It's not possible in Power Query M. Table.Combine make an union with columns that match. If you want to keep all in the same step you can add the change names step instead of tap2 like you did with Table.SelectColumns.
This comparison of matching names is to union in a correct way.
Hope you can manage in the same step if that's what you want.
I use Power BI to create reports and visuals for large enterprise clients.
I have an interesting request from one of my clients: they would like to be able to see a summary of all filters that are applied to a given report. I used the ISFILTERED() function to create a card visual that lists the dimensions that are filtered, but they would like to be able to see which values are being shown. This works just fine when they have sliced or filtered for just one value, but how can I show when more than one is selected? My DAX is below:
Applied Filters =
var myvalues = VALUES(mytable[dimension_column])
return
IF(ISFILTERED(mytable[dimension_column]) = FALSE(),
"Not filtered",
"Column Name:" & UNICHAR(10) & mylist)
When only one value is selected in the slicer, the output is:
Column Name:
Selected Value
Obviously, when more than one value is selected in the slicer, variable mylist will have more than one value and the function fails. My question is, how can I convert the column myvalue to a list in DAX, so I can output each and every value?
What I want to get is:
Column Name:
Selected Value1,
Selected Value2,
etc.
Thank you!
One possibility is to concatenate all the values into a single string.
For example, you'd replace mylist with the string
CONCATENATEX(VALUES(mytable[dimension_column]), mytable[dimension_column], UNICHAR(10))
You're really only returning a single value for the measure, but it looks like a column.
Another approach is, instead of using a card, to simply create a table visual that just has mytable[dimension_column] for the values. This table will automatically filter as you adust slicers.