I wrote a DAX query that include some different kind of measure in SSAS Tabular model. Now I have to break my solution in some pages for using in application and sort by my measures.
I used TOPNSKIP() function but can not creating table that sorted by measure.
DAX code:
EVALUATE
SELECTCOLUMNS(
TopnSkip ( 5,0,'Station',Station[StationTitle],asc),
"NameOfStation",Station[StationTitle],
"TradeSellPrice", [TradeSellPrice],
"TradePrice" ,[TradePrice],
BrokerCommission",[BrokerCommission])
Order by [TradePrice] asc
This code first select Top 5 from "Station" table and then sorted by "Tradeprice". This is not my expectation and what I need a solution sorted by "TradePrice".
EVALUATE
TOPNSKIP (
5, 0,
SELECTCOLUMNS (
'Station',
"NameOfStation", 'Station'[StationTitle],
"TradeSellPrice", [TradeSellPrice],
"TradePrice", [TradePrice],
"BrokerCommission", [BrokerCommission]
),
[TradePrice],
ASC
)
ORDER BY [TradePrice] ASC
First arg to SELECTCOLUMNS is a table. You passed it the table TOPNSKIP ( 5, 0, 'Station', 'Station'[StationTitle], ASC ), which is the 5-row table of the first five StationTitles.
Then, you defined the columns to select from that 5-row table. And finally you ordered the output of that table by [TradePrice].
TOPNSKIP takes a table as input. So pass it the table with the columns you need to define, and sort by any of them.
Related
So this question goes off the one here
I've been trying to do a similar count measure and I did the suggested solution but it's still running.... and it's been more than 30 minutes with no results, while without that it runs in under a minute. So am I missing something? Any guidance would help. Here is my query:
WITH
MEMBER [Measures].[IteractionCount] AS
NONEMPTY
(
FILTER
(
([DimInteraction].[InteractionId].[ALL].Children,
[Measures].[Impression Count]),
[DimInteraction].[Interaction State].&[Enabled]
)
).count
SELECT
(
{[Measures].[IteractionCount],
[Measures].[Impression Count]}
)
ON COLUMNS,
(
([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
[DimCampaign].[Campaign Name].[Campaign Name].MEMBERS,
[DimCampaign].[Owner].[Owner].MEMBERS)
,[DimDate].[date].[date].MEMBERS
)
ON ROWS
FROM
(
SELECT
(
{[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
)
ON COLUMNS
FROM [Model]
)
WHERE
(
{[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL},
[DimCampaign].[Campaign State].&[Active],
{[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
//[DimInteraction].[Interaction State].&[Enabled]
)
I don't know if FILTER is affecting it in any way but I tried it with and without and it still runs forever. I do need it specifically filtered to [DimInteraction].[Interaction State].&[Enabled]. I have also tried to instead filter to that option in the WHERE clause but no luck
Any suggestions to optimize this would be greatly appreciated! thanks!
UPDATE:
I end up using this query to load data into a python dataframe. Here is my code for that. I used this script for connecting and loading the data. I had to make some edits to it though to use windows authentication.
ssas_api._load_assemblies() #this uses Windows Authentication
conn = ssas_api.set_conn_string(server='server name',db_name='db name')
df = ssas_api.get_DAX(connection_string=conn, dax_string=query))
The dax_string parameter is what accepts the dax or mdx query to pull from the cube.
Please try this optimization:
WITH
MEMBER [Measures].[IteractionCount] AS
SUM
(
[DimInteraction].[InteractionId].[InteractionId].Members
* [DimInteraction].[Interaction State].&[Enabled],
IIF(
IsEmpty([Measures].[Impression Count]),
Null,
1
)
)
SELECT
(
{[Measures].[IteractionCount],
[Measures].[Impression Count]}
)
ON COLUMNS,
(
([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
[DimCampaign].[Campaign Name].[Campaign Name].MEMBERS,
[DimCampaign].[Owner].[Owner].MEMBERS)
,[DimDate].[date].[date].MEMBERS
)
PROPERTIES MEMBER_CAPTION
ON ROWS
FROM
(
SELECT
(
{[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
)
ON COLUMNS
FROM [Model]
)
WHERE
(
{[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL},
[DimCampaign].[Campaign State].&[Active],
{[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
//[DimInteraction].[Interaction State].&[Enabled]
)
CELL PROPERTIES VALUE
If that doesn’t perform well the please describe the number of rows returned by your query when you comment out IteractionCount (sic) from the columns axis. And please describe how many unique InteractionId values you have.
I'm trying to do a search using ordering and paging, but without success, I mean, it's works, but not like I was expecting
I'm doing a search like this:
WITH
MEMBER [Measures].[indexable_name] AS
[myDimension].[name].CurrentMember.UniqueName
SELECT
SubSet
(
Order
(
{
[myDimension].[id].MEMBERS
,[myDimension].[name].MEMBERS
}
,[Measures].[indexable_name]
,ASC
)
,0
,20
) ON ROWS
,{[Measures].[indexable_name]} ON COLUMNS
FROM [myCube];
that bring to me something like this
"nome" is the name of my item and indexable_name are the unique name
So, my problem is, when I'm doing the paging in my java code, I only can take half of what I want to, because I'm looking for two rows to take all the information that I need(id and name), there's some way to put all the information in one row to fix it?
You may join name of two attributes in one by an extra measure:
With
Member [Measures].[indexable_name] as
[myDimension].[name].CurrentMember.uniqueName
Member [Measures].[DimsName] as
[myDimension].[id].CurrentMember.Name + ' ' + [myDimension].[name].CurrentMember.Name
select
Subset(
Order(
{[myDimension].[id].Members,[myDimension].[name].Members},
[Measures].[indexable_name],ASC
),
0,
20
) on rows,
{[Measures].[DimsName],[Measures].[indexable_name]} on columns
from [myCube]
Good Day all.
I really hope someone can assist with this. The following code works great in DaxStudio and returns a topn table.
evaluate
TOPN(10,SUMMARIZE(factDailyPlay,factDailyPlay[PlayerAccountNumber],"Top10",SUM(factDailyPlay[ActualWin])),[Top10],0)
What I am trying to return in my model though is sum of those top 10 values as a single scalar value of that topn table.
I keep getting the following error.
The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
Thanks
Try using:
EVALUATE
ROW (
"Total", SUMX (
TOPN (
10,
SUMMARIZE (
factDailyPlay,
factDailyPlay[PlayerAccountNumber],
"Top10", SUM ( factDailyPlay[ActualWin] )
),
[Top10], 0
),
[Top10]
)
)
Basically the below expression calculates the sum you require.
SUMX (
TOPN (
10,
SUMMARIZE (
factDailyPlay,
factDailyPlay[PlayerAccountNumber],
"Top10", SUM ( factDailyPlay[ActualWin] )
),
[Top10], 0
),
[Top10]
)
I would like to order a set of results in an MDX query which also includes a crossjoin.
I have the following measures and dimensions:
[Measures].[Starts]
[Framework].[Framework Name]
[Framework].[Pathway Name]
I would like to create a list of the (corresponding) Framework and Pathway names that correspond to the top 25 numbers of [Measures].[Starts].
I have managed to output a FULL list of results using:
select [Measures].[Starts] on COLUMNS,
NON EMPTY CrossJoin(
Hierarchize({DrilldownLevel({[Framework].[Pathway Name].Children})}),
Hierarchize({DrilldownLevel({[Framework].[Framework Name].Children})})
) on ROWS
from [DataCube]
to create the following example output:
However, I need it to be sorted by the starts in descending order (and preferably only keep the top 25 results). I have tried almost everything and have failed. A google search didn't find any results.
Did you stumble across the TopCount function?
select [Measures].[Starts] on COLUMNS,
NON EMPTY
TopCount
(
CrossJoin
(
Hierarchize({DrilldownLevel({[Framework].[Pathway Name].Children})}),
Hierarchize({DrilldownLevel({[Framework].[Framework Name].Children})})
),
25,
[Measures].[Starts]
) on ROWS
from [DataCube]
Here's the msdn link.
H2H
For efficiency it is better to order the set before using the TopCount function:
WITH
SET [SetOrdered] AS
ORDER(
{DrilldownLevel([Framework].[Pathway Name].Children)}
*{DrilldownLevel([Framework].[Framework Name].Children)}
,[Measures].[Starts]
,BDESC
)
SET [Set25] AS
TOPCOUNT(
[SetOrdered]
,25
)
SELECT
[Measures].[Starts] on 0,
NON EMPTY
[Set25] on 1
FROM [DataCube];
HOw to retrieve FIRST (N) rows while retrieving a Table from Power Pivot with Dax?
What came to my mind is only to add an index column with Power Query and then to use FILTER() to enroll the SUMMARIZE()
My code:
EVALUATE
FILTER(
SUMMARIZE(
RTO_EnrolmentsAllCourses,
RTO_EnrolmentsAllCourses[CampusName],
RTO_EnrolmentsAllCourses[CoENo],
RTO_EnrolmentsAllCourses[Competency],
RTO_EnrolmentsAllCourses[Course_Finish],
RTO_EnrolmentsAllCourses[Course_start],
RTO_EnrolmentsAllCourses[CourseAttempt],
RTO_EnrolmentsAllCourses[CourseID],
RTO_EnrolmentsAllCourses[CourseName],
RTO_EnrolmentsAllCourses[Index]
),
RTO_EnrolmentsAllCourses[Index]<50)
Thanks in advance
Try this:
EVALUATE(
SAMPLE(
50,
RTO_EnrolmentsAllCourses,
RTO_EnrolmentsAllCourses[CampusName], 1,
RTO_EnrolmentsAllCourses[CoENo], 1
)
)
That returns the first 50 rows ordered by CampusName ascending (that's the value 1 right after CampusName) and CoENo ascending. You have to provide order by columns of you want a predictable 50 rows rather than a random 50 rows per the documentation.
Thanks, GregGalloway! It is working just fine. Enrolling SAMPLE () into SUMMARIZE() I just retrieve what I needed.
EVALUATE
SUMMARIZE(
SAMPLE(
10,
RTO_EnrolmentsAllCourses,
RTO_EnrolmentsAllCourses[CampusName], 1
),
RTO_EnrolmentsAllCourses[AgentName],
RTO_EnrolmentsAllCourses[CampusName]
)
Thanks again!