Can we use user defined hierarchy in DAX ? - tabular

Can we use user defined hierarchy in DAX and then EVALUATE to see the whole hierarchy items as result ?

There are no hierarchy functions in DAX. The best you can do is to just return a list of your hierarchy columns. So suppose you had a columns called Level1, Level2, and Level3 in a table called DaxTab. The best you could do to dump the contents of the hierarchy would be:
EVALUATE
SUMMARZE(
DaxTab,
[DaxTab]Level1,
[DaxTab]Level2,
[DaxTab]Level3
)
ORDER BY
[DaxTab]Level1,
[DaxTab]Level2,
[DaxTab]Level3

Related

How do I create a measure in Power Pivot that pulls a value from another table?

I have two tables that use a unique concatenated column for their relationship. I simply want to make a measure that uses the values from C4 of Table1. I thought I could use a simple formula like =values(Table1[C4]) but I get an error of "A table of multiple values was supplied where a single value was expected."
Side note: I realize the concatenation is unnecessary here in this simple example, but it is necessary in the full data I am working with which is why I added it into this example.
Here's a simplified set of tables for what I am trying to do:
Table1
Table2
Relationships
First you should think. Do I really need a Calculated column? Can't this be calculated at runtime?
But if you still want to do it, you can use RELATED or RELATEDTABLE.
Keep in mind if you are pulling from RELATEDTABLE, returns many values. So you should apply some type of aggregation like SUMX or MAXX.
You can use context transition to retrieve the value.
= CALCULATE(MAX(Table1[C4])

How to cube on two columns as if they were one?

I have a following attributes that I am interested on performing aggregations (regular count for example) on attributes:
'category', 'sub-category', age, city, education... (around 10 more)
I am interested in all possible combinations of the attributes in group by, so using dataframes cube function could help me achieve that.
But here is a catch: sub-category does not make any sense without category, so in order to achieve this I need to combine rollup(category, sub-category) with cube(age, city. education...).
How to do this?
This is what I tried, where test is the name of my table:
val data = sqlContext.sql("select category,'sub-category',age from test group by cube(rollup(category,'sub-category'), age )")
and this is the error I get:
org.apache.spark.sql.AnalysisException: expression 'test.category' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.;
I think what you want is struct or expr functions to combine two columns as one and use it to cube on.
With struct it'd be as follows:
df.rollup(struct("category", "sub-category") as "(cat,sub)")
With expr it's as simple as using "pure" SQL, i.e.
df.rollup(expr("(category, 'sub-category')") as "(cat,sub)")
But I'm just guessing...

DAX Formula (Using Join)

I'm looking to create a dax calculated column that uses two related tables. one is a dimension one is a fact. in MDX it looks like this:
Sum(
{[Tbl Master Measure Mapping].[Str Busies].[True]}
,[Measures].[Int Calls Offered]
)
in t-sql it looks like this:
select int_CallsOffered from fact_CallType_OTS a
inner join tbl_MasterMeasureMapping b on a.entName = b.entName
where b.Str_Busies = 'True'
Pretty Straight forward. This works in a cube no problem. How can i translate the above to a dax formula in power pivot ? would this be a measure or a calculated column ? i'm thinking calcualted column. I've looked on the internet, and a term "Evaluate" comes up, but i don't find that function in my version of power pivot. maybe i'm behind ? but i'd love to find a solution where i join just two tables (which i've defined the relationship on) and get a value back based on the where clause. Thanks.
b
You could create the measure using the CALCULATE function.
Call type OTS total:=CALCULATE(sum([Int Calls Offered]),'Tbl Master Measure Mapping'[Str Busies]=TRUE)
Note: your TSQL and MDX would not return the same thing as the TSQL is not aggregating
see https://msdn.https://msdn.microsoft.com/en-us/library/ee634825.aspx

SSAS, dimension numeric value filtering

I am using the multiple dimensional model in SSAS with a seemingly simple requirement.
I have a Product dimension table with a Price attribute. Using Excel pivot-table, I want to filter this Price attribute, for example "greater than $1000". However the filter in the pivot table is a string only, hence I can not do perform any numerical comparison operations, but rather for equivalent strings, e.g. "$1,000.00".
My problem is similar to this thread, and I wonder if there is a solution/work around that I missed?
Best regards,
CT
As suggested in the thread that you link, you could create a measure for the price, and then filter that. The definition of this calculated measure would be something like
[Product].[Product].Properties("Price", TYPED)
assuming the dimension as well as the attribute are named "Product", and the attribute has the price defined as a property named "Price".
(You define a property in BIDS as a relationship from the Product attribute to the Priice attribute.)

Dynamics AX Nested Query

Maybe I'm missing something simple, but is there a way to write a nested query in AX? I tried some syntax I thought would work, but with no luck.
The following standard SQL statement would accomplish what I'm trying to do, but I need to do this in AX, not SQL.
SELECT table1.column1A, table1.column1B,
(SELECT Top 1 column2B FROM table2
WHERE table1.column1A = table2.column2A
ORDER BY table2.column1A)
AS lookupResult
FROM table1
My problem is that table1 has a one-to-many relationship with table2, and since AX doesn't have a DISTINCT function that I'm aware of, I receive many copies of each record when using a JOIN statement.
Thanks
Nested queries are not supported in AX.
One way to bypass the missing distinct is to use group by (assuming max value of column2B is interesting):
while select column1A, column1B from table1
group column1A, column1B
join max-of(column2B) from table2
where table2.column2A == table1.column1A
{
...
}
Another method would be use a display method on table1 in the form or report.
display ColumnB column2B()
{
return (select max-of(column2B) from table2
where table2.column2A == this.column1A).column2A;
}
The performance is inferior to the first solution, but it may be acceptable.
As mentioned in the previous reply, group-by is the closest you can get to a distinct function. If you need a simpler query for some reason, or if you need a table or query object to use as a datasource on a form or report, you may entertain the idea of creating a view in the AOT, which contains the group-by. You can then use that view to easily join to on a query object or form datasource etc...
Ax2012 has support of computed columns in views, you can use the SysComputedColumn class to build query you want

Resources